-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mir: add a dedicated handle conversion operation (#935)
## Summary Introduce a dedicated handle conversion operator (`mnkPathConv`) to the MIR, leaving `mnkConv` to only represent conversions producing new (non handle-like) values. This clarifies the semantics around MIR-level conversions a bit, fixing the internal-only issue of `mnkConv` and `mnkStdConv` being sometimes treated as if they always represented handle conversion. ## Details A value conversion (e.g., `int(f)` where `f` is a float value) produces a new value -- the result cannot be assigned to. A *handle* conversion produces a new *handle* to the same location as that of the input value. The distinction is important at the MIR level, as it affects ownership and evaluation semantics. `mnkConv` was previously used to represent both kinds of conversions, but since the type comparison required for detecting the conversion kind is rather costly, `mnkConv` was so far almost always treated as the one the context required. The current structure of the MIR lets one get away with this, but it's still incorrect, and it's also in the way of MIR improvements. In addition, `mnkStdConv` always represents value conversions, and it being used/skipped where `mnkConv` is treated as a handle conversion is always wrong. In order to remove the ambiguity, the new `mnkPathConv` operator is introduced. Since it too represents a path/projection, it is grouped together with the other path operations. For simplicity, `mnkPathConv` also applies to first-class handle-like values (`ref`, `ptr`, `var`, etc.) for now -- they are presently treated the same as L-value conversions. * add the `mnkPathConv` operation. Syntax-wise, it's a single-input, result-yielding operation * add `mnkPathConv` support to the MIR construction DSL * emit an `mnkPathConv` instead of `mnkConv` for object/ref up- and down-conversions * emit a `mnkPathConv` instead of `mnkConv` for conversions between distinct types and their base (and vice versa) The places where `mnkConv` was previously treated as a handle conversions are changed to use `mnkPathConv`. `mirpasses.isRvalue`, which had to conservatively exclude it previously, now includes the `mnkConv` operation. There's also an issue in `transf` that had to be fixed: all up- and down- conversions are expected to use `nkObjUpConv` and `nkObjDownConv` nodes past `transf` (see `transformConv`), but lowering an exception handler branch (`transformExceptBranch`) emitted a raw `nkHiddenSubConv` for down conversions.
- Loading branch information
Showing
10 changed files
with
59 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters