Track the file kind on SourceLocation rather than computing it from the file name. (#2999)

This will be more correct if a user file is named prelude.carbon, and
reduces the explorer runtime by about 10% by removing a string
comparison from the check for whether trace output is enabled.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2023-07-19 23:07:53 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 41e357492b
commit ea60e4f491
29 changed files with 168 additions and 146 deletions
@@ -93,7 +93,7 @@ auto ParseAndExecuteFile(std::string_view prelude_path,
Nonnull<llvm::raw_ostream*> print_stream)
-> ErrorOr<int> {
auto parse = [&](Arena* arena) {
return Parse(arena, input_file_name, parser_debug);
return Parse(arena, input_file_name, FileKind::Main, parser_debug);
};
return ParseAndExecuteHelper(parse, prelude_path, trace_stream, print_stream);
}
@@ -104,7 +104,8 @@ auto ParseAndExecute(std::string_view prelude_path,
Nonnull<TraceStream*> trace_stream,
Nonnull<llvm::raw_ostream*> print_stream) -> ErrorOr<int> {
auto parse = [&](Arena* arena) {
return ParseFromString(arena, input_file_name, file_contents, parser_debug);
return ParseFromString(arena, input_file_name, FileKind::Main,
file_contents, parser_debug);
};
return ParseAndExecuteHelper(parse, prelude_path, trace_stream, print_stream);
}