Conversation
Merged
This was referenced Apr 14, 2023
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull-request initiates the support for explicit region annotations. The idea is to implement a system that is compatible with using plain Standard ML and in particular in such a way that Standard ML code compiled with the MLKit with regions can work well with the enriched source code files.
We use
Dto range over numbers,Fto range over floating point numbers,Sto range over strings, andCto range over constructors. Here is a summary of the added syntactic features:Notice that immediate integers cannot be annotated (integers are not boxed) whereas strings and reals can.
Trying it
The added syntactic forms are supported when the
mlkitexecutable is passed the flag--explicit_regions(short:-er). Consider compiling the fileer1.sml:Here is the result:
Features
regiondeclarations.CompileDecto compile region declarations into aletregion r in econstruct.CompileDecto compile allocation annotations properly.LambdaExptoRegionExp, we need to make sure that the region annotations are enforced, which could result in error messages.OptLambdapreserves the region annotations when performing optimisations.Future Features
Here is a list of some wishful future features:
Support for region annotations in types:
Extend
CompileDecto compile region annotations in types into region annotations inLambdaExptypes.We would also like support for writing effects in types.
Make sure that
OptLambdapreserves the type annotations when performing optimisations, which can be tricky.Design decisions
Do not associate explicit region variables with region types.
We could support that an explicit region variable is associated with a region type, which would allow the compiler to check early (before explicit region variables are associated with proper region variables) the consistent use of region variables. We could also just leave this check to the proper region variable system, which is what is implemented.
Early checks. Another obvious strategy is to check early certain properties of the region annotations (before SpreadExpression and RegInf). Here are some properties we can check at ElabDec level:
regiondecsgreg_top,greg_pair,greg_triple,greg_string, andgreg_refare in scope.)LambdaExplevel. At theLambdaExplevel, however, we need to be more clever, asOptLambdais performing inlining and such, which may require us to perform renaming of region variables.We can leave other elaboration issues to the lower levels (
LambdaExpandSpreadExpression/RegInf).Further Ideas
mlkitcould supportrml-files (Region ML) and enable the flag-erimplicitly.