-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support CallerArgumentExpression
(without #line
)
#17519
base: main
Are you sure you want to change the base?
Conversation
❗ Release notes required
|
…Tangent-90/fsharp into SupportCallerArgumentExpression
Here I encounter a problem about #1 "C:\\Program.fs"
System.ArgumentNullException.ThrowIfNullOrWhiteSpace(" ") // will failed to build
// And more complicated case, repeat the file name and line number
#1 "C:\\Program.fs"
System.ArgumentNullException.ThrowIfNullOrWhiteSpace(" ") // will failed to build So here I want to get the original |
Simplify code
add warning read the new line mark
…Tangent-90/fsharp into SupportCallerArgumentExpression
src/Compiler/Utilities/range.fs
Outdated
| _ -> String.Empty | ||
} | ||
|
||
let getCodeText (m: range) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether it would be possible to use ISourceText.GetSubTextString
instead of all of this. I think the ISourceText
for a given file will usually already be cached when this functionality is needed.
I think in theory the source text is available on cenv.tcSink.CurrentSink.Value.CurrentSourceText.Value
, but maybe there's a better way to get it, or a better way to bring it in scope for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would make sense to pass it in, then, as is done when checking format strings:
fsharp/src/Compiler/Checking/NameResolution.fs
Lines 1777 to 1779 in 0a715a5
type FormatStringCheckContext = | |
{ SourceText: ISourceText | |
LineStartPositions: int[] } |
fsharp/src/Compiler/Checking/CheckFormatStrings.fs
Lines 67 to 73 in 0a715a5
let makeFmts (context: FormatStringCheckContext) (fragRanges: range list) (fmt: string) = | |
// Splits the string on interpolation holes based on fragment ranges. | |
// Returns a list of tuples in the form of: offset * fragment as a string * original range of the fragment | |
// where "offset" is the offset between beginning of the original range and where the string content begins | |
let numFrags = fragRanges.Length | |
let sourceText = context.SourceText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would make sense to pass it in, then, as is done when checking format strings:
I guess maybe that's the same source text as in the sink... But still, maybe there's somewhere else we could put it.
CallerArgumentExpression
CallerArgumentExpression
(without #line
)
This is ready for both the The |
I propose to merge this in as is with the This PR does come under a LanguageFeature flag and we could offer the feature for real world testing under the preview version. |
@@ -671,6 +671,9 @@ let main1 | |||
// Build the initial type checking environment | |||
ReportTime tcConfig "Typecheck" | |||
|
|||
// Read the source file content for the `CallerArgumentExpression` feature | |||
readAndStoreFileContents tcConfig sourceFiles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a "ReportTime" section here so that we can see impact on timing in selected compilations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Especially something bigger, like when the compiler compiles itself (this will need the --times
flag to report the timings)
let readAndStoreFileContents (tcConfig: TcConfig) (sourceFiles: #seq<string>) = | ||
for fileName in sourceFiles do | ||
if FSharpImplFileSuffixes |> List.exists (FileSystemUtils.checkSuffix fileName) then | ||
try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about FileContent
storing not allocated strings, but rather lazy objects?
Assumption is that majority of content will never be needed,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still wonder there is any way we could pass in an existing ISourceText
somehow, as suggested in #17519 (comment). But maybe it's just too hard to thread it through to where it needs to be.
src/Compiler/Utilities/range.fs
Outdated
|
||
/// Get the substring of the given range. | ||
/// This can retain the line seperators in the source string. | ||
let substring (input: string) (range: range) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the main usage of fileContentDict
is to identify expressions based on a range:
- I would for sure make it lazy to prevent allocating massive strings which no one will read
- Wouldn't the algorithm be a lot simpler if that lazy storage worked with an array of lines instead of a single string? (writing that now, I do realize this would drop the ability to keep original line endings, wouldn't it?)
@@ -581,3 +581,83 @@ module Range = | |||
| None -> mkRange file (mkPos 1 0) (mkPos 1 80) | |||
with _ -> | |||
mkRange file (mkPos 1 0) (mkPos 1 80) | |||
|
|||
module internal FileContent = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel uneasy with this module.
- It adds a global resource for a rather local feature.
- It creates another dependency on the file system.
- It re-reads sources from the file system that have been read before.
Getting the source text out of the checking environment as proposed by @brianrourkeboll would be much cleaner.
A (probably too ambitious) alternative would be to make this a central place for source access, to give ISourceText the role that it was meant to have and to remove file system access elsewhere.
Description
Implements fsharp/fslang-suggestions#966
RFC fsharp/fslang-design#798
Checklist