Implement autofilled source loc magic constants#8303
Open
Conversation
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
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 PR adds an opt-in way to automatically capture call site information at runtime. It does so by introducing two new builtin abstract types:
sourceLocPosandsourceLocValuePath.The opt-in is explicit at the function definition site: if you want one of these arguments to be compiler-filled, you declare it with
%autofill, for example~pos: sourceLocPos=%autofill. If%autofillis not present, the argument is just a regular argument. When the feature is enabled and such an argument is omitted at the call site, the compiler automatically injects information about the call site into it.The two builtin types contain different kinds of call site information:
sourceLocPosgives a string like<file>;<startLine>;<startCol>;<endLine>;<endCol>sourceLocValuePathgives a string likeModule.Submodule.value.localBinding, pointing to the value path of the call in the fileBoth of these types are abstract. To extract meaningful information from them, this PR also adds a new stdlib module,
SourceLoc, with helpers for interacting withsourceLocPosandsourceLocValuePath. These helpers can turn the abstract values into their underlying strings, or decode them into richer structures.This feature is intended for things like:
Configuration
This should eventually become a proper configuration, but for now it is opt-in and enabled by passing this to
bsc:The two opt-in points are intentional:
%autofillmakes it obvious at a glance which arguments are intended to be compiler-filled-allow-autofill-source-locenables the actual call-site injectionIf
-allow-autofill-source-locis not enabled, omitted%autofillarguments fall back to an empty string representation instead of receiving injected call site information. So code using these values should handle the “off” case gracefully.Examples
What each type means: