ir: Field instructions are too high-level

Bug #690017 reported by Matt Giuca
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mars
Fix Released
High
Matt Giuca

Bug Description

The current field access instructions at the Mars assembly level (ld_field, i_fieldset and i_fieldreplace) are too high-level. They include a mapping from constructor names to field IDs, with a user-level error message if they fail. This implies that not only is the back-end expected to switch over the constructors of the value and behave accordingly, but that it must also present a user-level message (failure is part of the semantics as opposed to undefined behaviour).

This is far too high-level, and very hard to optimise. For example, the front-end may know for sure the constructor a certain value has (it may have just come out of a switch), but it still has to generate a field instruction with an error message, and the back-end is still required to check the constructor and produce the message if it doesn't match. In this situation, the front-end should be able to define behaviour only in the case of that constructor, with undefined behaviour if there is any other constructor.

It is also very hard to generate code for. For example, in the LLVM backend, the code generator will need to create new basic blocks and switch instructions just for a single Mars instruction.

The three field access instructions should each have the following changes:
- Replace the ctor: field_idx mapping with a (ctor, field_idx) pair.
- Remove the error message.

Now each field access instruction only has well-defined behaviour if the value has the same ctor as mentioned in the instruction. For any other constructor, behaviour is undefined and the back-end is allowed to do anything (hence, a nice message is not supplied).

If the front-end knows for sure which constructor, it only has to generate a single field access instruction. If it does not know for sure, then it is the responsibility of the front-end to generate a Mars-assembly-level switch statement with the appropriate action in each case, including error messages.

Tags: ir

Related branches

Matt Giuca (mgiuca)
Changed in mars:
status: Triaged → In Progress
Revision history for this message
Matt Giuca (mgiuca) wrote :

Fixed in trunk r1167.

Changed in mars:
status: In Progress → Fix Committed
Matt Giuca (mgiuca)
Changed in mars:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.