Skip to content
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

Backwards merging #368

Merged
merged 43 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b5276a2
Merge pull request #365 from Luthetus/beta
Luthetus Dec 10, 2024
3bcc03b
Merge pull request #49 from Luthetus/staging
huntercfreeman Dec 10, 2024
c446e09
Update versions
huntercfreeman Dec 10, 2024
f71df1d
ImmutableArray to Array 1 to 2 seconds off entire solution parse
huntercfreeman Dec 11, 2024
048c727
Override 'ParseAsync' 1 to 2 seconds off entire solution parse
huntercfreeman Dec 11, 2024
563c013
My measurements are not precise so I'm going with my gut that this is…
huntercfreeman Dec 11, 2024
a63fb15
Binder only 2 constructor invocations (was 1,816)
huntercfreeman Dec 11, 2024
1dab5b9
Idea
huntercfreeman Dec 11, 2024
3ba3fac
CSharpLexer is struct: 34.9s
huntercfreeman Dec 11, 2024
a9f9a35
Parse is struct 36s (but very nonscientific measurements are being done)
huntercfreeman Dec 11, 2024
08b8eff
Track counts in debug mode
huntercfreeman Dec 11, 2024
d07de17
Changes in place in order to optimize CompilationUnit (nothing actual…
huntercfreeman Dec 12, 2024
6565148
DOES NOT BUILD: Changing code to use CSharpCompilationUnit.cs
huntercfreeman Dec 12, 2024
9ad8732
DOES NOT BUILD: Still changing IParserModel arguments to CSharpCompil…
huntercfreeman Dec 12, 2024
70f7737
Most arguments are fixed to use CSharpCompilationUnit
huntercfreeman Dec 12, 2024
f647ddf
DOES NOT BUILD: Fixing usages of model. to be 'compilationUnit.Parser…
huntercfreeman Dec 12, 2024
729dab1
DOES NOT BUILD: Replacing model. with 'compilationUnit.ParserModel.'
huntercfreeman Dec 12, 2024
e3a4a0a
DOES NOT BUILD: Got all the 'model.' but still more changes need to b…
huntercfreeman Dec 12, 2024
13b1c53
DOES NOT BUILD: Fixing 'model)' to 'compilationUnit)'
huntercfreeman Dec 12, 2024
7177aa7
DOES NOT BUILD: More fixing 'model)' to 'compilationUnit)'
huntercfreeman Dec 12, 2024
441dc28
DOES NOT BUILD: Changed 'model)' to 'compilationUnit)'
huntercfreeman Dec 12, 2024
ce4604a
DOES NOT BUILD: change remaining 'model' references to 'compilationUn…
huntercfreeman Dec 12, 2024
0608111
DOES NOT BUILD: fix initial using statement errors.
huntercfreeman Dec 12, 2024
555d4f0
DOES NOT BUILD: inter-project related errors remain
huntercfreeman Dec 12, 2024
96e84ed
This surprisingly runs, I broke the tooltip since CSharpBinder doesn'…
huntercfreeman Dec 12, 2024
fd1535f
Catch exception in SymbolDisplay.razor.cs
huntercfreeman Dec 12, 2024
6a78c2f
All works again?
huntercfreeman Dec 12, 2024
2f8b728
Lexer Inlining some function calls to see what the effect is
huntercfreeman Dec 13, 2024
9416750
Create 'LexerKeywords' once
huntercfreeman Dec 13, 2024
0e67722
ALL_KEYWORDS_HASH_SET
huntercfreeman Dec 13, 2024
000a0ea
Fix: accidentally made "everything" a keyword
huntercfreeman Dec 13, 2024
9b3a97d
CSharpLexer.cs: Remove unused function arguments
huntercfreeman Dec 13, 2024
6a210fa
ref struct?
huntercfreeman Dec 13, 2024
3b50b95
ref this?
huntercfreeman Dec 13, 2024
612c29d
Rename local variable to follow naming convention
huntercfreeman Dec 13, 2024
9a494de
Track how long lexer takes
huntercfreeman Dec 13, 2024
a203998
ApplySyntaxHighlighting is the issue it takes 20 seconds
huntercfreeman Dec 13, 2024
485b4c0
Remove timing code
huntercfreeman Dec 13, 2024
3b50db2
Don't syntax highlight during solution wide parse
huntercfreeman Dec 13, 2024
7afd06f
_hasBeenDisplayedAtLeastOnceBefore
huntercfreeman Dec 13, 2024
02ccc45
Update IdeInfoDisplay.razor
huntercfreeman Dec 13, 2024
47dfcb5
Merge pull request #366 from huntercfreeman/optimizations
Luthetus Dec 13, 2024
6d83c08
Merge pull request #367 from Luthetus/staging
Luthetus Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Lib/CompilerServices/C/CLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CLexer(ResourceUri resourceUri, string sourceText)
: base(
resourceUri,
sourceText,
new LexerKeywords(CLanguageFacts.Keywords.ALL_LIST, CLanguageFacts.Keywords.CONTROL_KEYWORDS, ImmutableArray<string>.Empty))
new LexerKeywords(CLanguageFacts.Keywords.ALL_LIST, CLanguageFacts.Keywords.CONTROL_KEYWORDS, Array.Empty<string>()))
{
_cSyntaxTree = new GenericSyntaxTree(CLanguageDefinition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Keywords
public const string VOLATILE_KEYWORD = "volatile";
public const string WHILE_KEYWORD = "while";

public static readonly ImmutableArray<string> ALL_LIST = new[]
public static readonly string[] ALL_LIST = new[]
{
AUTO_KEYWORD,
BREAK_KEYWORD,
Expand Down Expand Up @@ -73,9 +73,9 @@ public class Keywords
VOID_KEYWORD,
VOLATILE_KEYWORD,
WHILE_KEYWORD,
}.ToImmutableArray();
};

public static readonly ImmutableArray<string> CONTROL_KEYWORDS = new[]
public static readonly string[] CONTROL_KEYWORDS = new[]
{
BREAK_KEYWORD,
CASE_KEYWORD,
Expand All @@ -88,6 +88,6 @@ public class Keywords
RETURN_KEYWORD,
SWITCH_KEYWORD,
WHILE_KEYWORD,
}.ToImmutableArray();
};
}
}
395 changes: 198 additions & 197 deletions Source/Lib/CompilerServices/CSharp/BinderCase/CSharpBinder.Expressions.cs

Large diffs are not rendered by default.

596 changes: 307 additions & 289 deletions Source/Lib/CompilerServices/CSharp/BinderCase/CSharpBinder.Main.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public CSharpBinderSession(
int globalScopeIndexKey,
NamespaceStatementNode topLevelNamespaceStatementNode)
{
#if DEBUG
++LuthetusDebugSomething.BinderSession_ConstructorInvocationCount;
#endif

ResourceUri = resourceUri;
Binder = binder;
CurrentScopeIndexKey = globalScopeIndexKey;
Expand All @@ -40,10 +44,9 @@ public CSharpBinderSession(
public Dictionary<ScopeKeyAndIdentifierText, FunctionDefinitionNode> ScopeFunctionDefinitionMap { get; } = new();
public Dictionary<ScopeKeyAndIdentifierText, IVariableDeclarationNode> ScopeVariableDeclarationMap { get; } = new();
public Dictionary<int, TypeClauseNode> ScopeReturnTypeClauseNodeMap { get; } = new();

IBinder IBinderSession.Binder => Binder;
int IBinderSession.CurrentScopeIndexKey { get => CurrentScopeIndexKey; set => CurrentScopeIndexKey = value; }

IBinder IBinderSession.Binder => Binder;

public int GetNextIndexKey()
{
return ++_indexKey;
Expand Down
24 changes: 16 additions & 8 deletions Source/Lib/CompilerServices/CSharp/CSharpKeywords.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using Luthetus.TextEditor.RazorLib.CompilerServices;

namespace Luthetus.CompilerServices.CSharp;

Expand Down Expand Up @@ -128,7 +129,7 @@ public class CSharpKeywords
public const string WITH_KEYWORD = "with";
public const string YIELD_KEYWORD = "yield";

public static readonly ImmutableArray<string> NON_CONTEXTUAL_KEYWORDS = new[]
public static readonly string[] NON_CONTEXTUAL_KEYWORDS = new[]
{
ABSTRACT_KEYWORD,
AS_KEYWORD,
Expand Down Expand Up @@ -207,9 +208,9 @@ public class CSharpKeywords
VOID_KEYWORD,
VOLATILE_KEYWORD,
WHILE_KEYWORD,
}.ToImmutableArray();
};

public static readonly ImmutableArray<string> CONTROL_KEYWORDS = new[]
public static readonly string[] CONTROL_KEYWORDS = new[]
{
BREAK_KEYWORD,
CASE_KEYWORD,
Expand All @@ -225,9 +226,9 @@ public class CSharpKeywords
THROW_KEYWORD,
WHILE_KEYWORD,
YIELD_KEYWORD
}.ToImmutableArray();
};

public static readonly ImmutableArray<string> CONTEXTUAL_KEYWORDS = new[]
public static readonly string[] CONTEXTUAL_KEYWORDS = new[]
{
ADD_KEYWORD,
AND_KEYWORD,
Expand Down Expand Up @@ -272,9 +273,16 @@ public class CSharpKeywords
WHERE_KEYWORD,
WITH_KEYWORD,
YIELD_KEYWORD,
}.ToImmutableArray();
};

public static readonly ImmutableArray<string> ALL_KEYWORDS = NON_CONTEXTUAL_KEYWORDS
public static readonly string[] ALL_KEYWORDS = NON_CONTEXTUAL_KEYWORDS
.Union(CONTEXTUAL_KEYWORDS)
.ToImmutableArray();
.ToArray();

public static readonly HashSet<string> ALL_KEYWORDS_HASH_SET = new(ALL_KEYWORDS);

public static readonly LexerKeywords LexerKeywords = new LexerKeywords(
NON_CONTEXTUAL_KEYWORDS,
CONTROL_KEYWORDS,
CONTEXTUAL_KEYWORDS);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Immutable;
using Luthetus.TextEditor.RazorLib.CompilerServices;
using Luthetus.TextEditor.RazorLib.CompilerServices.Implementations;
using Luthetus.TextEditor.RazorLib.CompilerServices.Interfaces;
using Luthetus.TextEditor.RazorLib.CompilerServices.Syntax.Nodes;
using Luthetus.TextEditor.RazorLib.Lexers.Models;
using Luthetus.CompilerServices.CSharp.LexerCase;
using Luthetus.CompilerServices.CSharp.ParserCase;
using Luthetus.CompilerServices.CSharp.BinderCase;

namespace Luthetus.CompilerServices.CSharp.CompilerServiceCase;

public sealed class CSharpCompilationUnit : ICompilationUnit
{
public CSharpCompilationUnit(
ResourceUri resourceUri,
CSharpBinder binder)
{
ResourceUri = resourceUri;
Binder = binder;
}

public ResourceUri ResourceUri { get; set; }
public CSharpLexer Lexer { get; set; }
public CSharpParser Parser { get; set; }
public CSharpParserModel ParserModel { get; set; }
public CSharpBinder Binder { get; set; }
public CSharpBinderSession BinderSession { get; set; }
public CodeBlockNode RootCodeBlockNode { get; set; }
public ImmutableArray<TextEditorDiagnostic> DiagnosticsList { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System.Collections.Immutable;
using Luthetus.Common.RazorLib.Keys.Models;
using Luthetus.TextEditor.RazorLib;
using Luthetus.TextEditor.RazorLib.Exceptions;
using Luthetus.TextEditor.RazorLib.Autocompletes.Models;
using Luthetus.TextEditor.RazorLib.CompilerServices;
using Luthetus.TextEditor.RazorLib.CompilerServices.Interfaces;
using Luthetus.TextEditor.RazorLib.CompilerServices.Implementations;
using Luthetus.TextEditor.RazorLib.CompilerServices.Facts;
using Luthetus.TextEditor.RazorLib.CompilerServices.Syntax.Nodes;
using Luthetus.TextEditor.RazorLib.Cursors.Models;
using Luthetus.TextEditor.RazorLib.Lexers.Models;
using Luthetus.TextEditor.RazorLib.TextEditors.Models;
Expand All @@ -23,29 +28,23 @@ public sealed class CSharpCompilerService : CompilerService
public CSharpCompilerService(ITextEditorService textEditorService)
: base(textEditorService)
{
Binder = CSharpBinder;

#if DEBUG
++LuthetusDebugSomething.CompilerService_ConstructorInvocationCount;
#endif

Binder = CSharpBinder;

_compilerServiceOptions = new()
{
RegisterResourceFunc = resourceUri => new CSharpResource(resourceUri, this),
GetLexerFunc = (resource, sourceText) => new CSharpLexer(resource.ResourceUri, sourceText),
GetParserFunc = (resource, lexer) => new CSharpParser((CSharpLexer)lexer),
GetBinderFunc = (resource, parser) => Binder,
OnAfterLexAction = (resource, lexer) =>
{
var cSharpResource = (CSharpResource)resource;
var cSharpLexer = (CSharpLexer)lexer;

cSharpResource.EscapeCharacterList = cSharpLexer.EscapeCharacterList;
},
};

RuntimeAssembliesLoaderFactory.LoadDotNet6(CSharpBinder);
}

public override Type? SymbolRendererType { get; protected set; }
public override Type? DiagnosticRendererType { get; protected set; }

public event Action? CursorMovedInSyntaxTree;

public void SetSymbolRendererType(Type? symbolRendererType)
Expand All @@ -57,6 +56,72 @@ public void SetDiagnosticRendererType(Type? diagnosticRendererType)
{
DiagnosticRendererType = diagnosticRendererType;
}

public override Task ParseAsync(ITextEditorEditContext editContext, TextEditorModelModifier modelModifier, bool shouldApplySyntaxHighlighting)
{
var resourceUri = modelModifier.ResourceUri;

if (!_resourceMap.ContainsKey(resourceUri))
return Task.CompletedTask;

_textEditorService.ModelApi.StartPendingCalculatePresentationModel(
editContext,
modelModifier,
CompilerServiceDiagnosticPresentationFacts.PresentationKey,
CompilerServiceDiagnosticPresentationFacts.EmptyPresentationModel);

var presentationModel = modelModifier.PresentationModelList.First(
x => x.TextEditorPresentationKey == CompilerServiceDiagnosticPresentationFacts.PresentationKey);

var cSharpCompilationUnit = new CSharpCompilationUnit(resourceUri, CSharpBinder);
cSharpCompilationUnit.Lexer = new CSharpLexer(resourceUri, presentationModel.PendingCalculation.ContentAtRequest);
cSharpCompilationUnit.Lexer.Lex();

// Even if the parser throws an exception, be sure to
// make use of the Lexer to do whatever syntax highlighting is possible.
try
{
cSharpCompilationUnit.BinderSession = (CSharpBinderSession)CSharpBinder.StartBinderSession(resourceUri);
var parser = new CSharpParser();
parser.Parse(cSharpCompilationUnit);
}
finally
{
lock (_resourceMapLock)
{
if (_resourceMap.ContainsKey(resourceUri))
{
var resource = (CSharpResource)_resourceMap[resourceUri];

resource.EscapeCharacterList = cSharpCompilationUnit.Lexer.EscapeCharacterList;
resource.SyntaxTokenList = cSharpCompilationUnit.Lexer.SyntaxTokenList;

if (cSharpCompilationUnit is not null)
resource.CompilationUnit = cSharpCompilationUnit;
}
}

var diagnosticTextSpans = GetDiagnosticsFor(modelModifier.ResourceUri)
.Select(x => x.TextSpan)
.ToArray();

modelModifier.CompletePendingCalculatePresentationModel(
CompilerServiceDiagnosticPresentationFacts.PresentationKey,
CompilerServiceDiagnosticPresentationFacts.EmptyPresentationModel,
diagnosticTextSpans);

if (shouldApplySyntaxHighlighting)
{
editContext.TextEditorService.ModelApi.ApplySyntaxHighlighting(
editContext,
modelModifier);
}

OnResourceParsed();
}

return Task.CompletedTask;
}

public override List<AutocompleteEntry> GetAutocompleteEntries(string word, TextEditorTextSpan textSpan)
{
Expand All @@ -72,7 +137,7 @@ public override List<AutocompleteEntry> GetAutocompleteEntries(string word, Text
while (targetScope is not null)
{
autocompleteEntryList.AddRange(
CSharpBinder.GetVariableDeclarationNodesByScope(model: null, textSpan.ResourceUri, targetScope.IndexKey)
CSharpBinder.GetVariableDeclarationNodesByScope(compilationUnit: null, textSpan.ResourceUri, targetScope.IndexKey)
.Select(x => x.IdentifierToken.TextSpan.GetText())
.ToArray()
.Where(x => x.Contains(word, StringComparison.InvariantCulture))
Expand All @@ -87,7 +152,7 @@ public override List<AutocompleteEntry> GetAutocompleteEntries(string word, Text
}));

autocompleteEntryList.AddRange(
CSharpBinder.GetFunctionDefinitionNodesByScope(model: null, textSpan.ResourceUri, targetScope.IndexKey)
CSharpBinder.GetFunctionDefinitionNodesByScope(compilationUnit: null, textSpan.ResourceUri, targetScope.IndexKey)
.Select(x => x.FunctionIdentifierToken.TextSpan.GetText())
.ToArray()
.Where(x => x.Contains(word, StringComparison.InvariantCulture))
Expand All @@ -104,7 +169,7 @@ public override List<AutocompleteEntry> GetAutocompleteEntries(string word, Text
if (targetScope.ParentIndexKey is null)
targetScope = null;
else
targetScope = CSharpBinder.GetScopeByScopeIndexKey(model: null, textSpan.ResourceUri, targetScope.ParentIndexKey.Value);
targetScope = CSharpBinder.GetScopeByScopeIndexKey(compilationUnit: null, textSpan.ResourceUri, targetScope.ParentIndexKey.Value);
}

var allTypeDefinitions = CSharpBinder.AllTypeDefinitions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
using System.Collections.Immutable;
using Luthetus.TextEditor.RazorLib.CompilerServices;
using Luthetus.TextEditor.RazorLib.CompilerServices.Interfaces;
using Luthetus.TextEditor.RazorLib.CompilerServices.Syntax;
using Luthetus.TextEditor.RazorLib.Lexers.Models;

namespace Luthetus.CompilerServices.CSharp.CompilerServiceCase;

public class CSharpResource : CompilerServiceResource
public sealed class CSharpResource : ICompilerServiceResource
{
public CSharpResource(ResourceUri resourceUri, CSharpCompilerService cSharpCompilerService)
: base(resourceUri, cSharpCompilerService)
{
ResourceUri = resourceUri;
CompilerService = cSharpCompilerService;
}


public ResourceUri ResourceUri { get; }
public ICompilerService CompilerService { get; }
public CSharpCompilationUnit? CompilationUnit { get; set; }
public IReadOnlyList<ISyntaxToken> SyntaxTokenList { get; set; } = ImmutableArray<ISyntaxToken>.Empty;
public IReadOnlyList<TextEditorTextSpan> EscapeCharacterList { get; internal set; }

public override IReadOnlyList<TextEditorTextSpan> GetTokenTextSpans()

ICompilationUnit? ICompilerServiceResource.CompilationUnit => CompilationUnit;

public IReadOnlyList<ISyntaxToken> GetTokens()
{
return SyntaxTokenList;
}

public IReadOnlyList<TextEditorTextSpan> GetTokenTextSpans()
{
var tokenTextSpanList = new List<TextEditorTextSpan>();

Expand All @@ -22,4 +36,30 @@ public override IReadOnlyList<TextEditorTextSpan> GetTokenTextSpans()

return tokenTextSpanList;
}

public IReadOnlyList<ITextEditorSymbol> GetSymbols()
{
var localCompilationUnit = CompilationUnit;

if (localCompilationUnit is null)
return Array.Empty<ITextEditorSymbol>();

return localCompilationUnit.Binder.Symbols
.Where(s => s.TextSpan.ResourceUri == ResourceUri)
.ToArray();
}

public IReadOnlyList<TextEditorDiagnostic> GetDiagnostics()
{
var localCompilationUnit = CompilationUnit;

if (localCompilationUnit is null)
return Array.Empty<TextEditorDiagnostic>();

// TODO: (2024-12-12)
/*return localCompilationUnit.DiagnosticsList
.Where(s => s.TextSpan.ResourceUri == ResourceUri)
.ToArray();*/
return Array.Empty<TextEditorDiagnostic>();
}
}
Loading
Loading