Skip to content

Commit

Permalink
workaround for merge conflicts add kernel library modules in compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Jan 17, 2025
1 parent 8fb274e commit 9eb31ec
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
54 changes: 49 additions & 5 deletions implement/pine/ElmInteractive/InteractiveSessionPine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,40 @@ public static TreeNodeWithStringPath MergeDefaultElmCoreAndKernelModules(
TreeNodeWithStringPath appCodeTree,
TreeNodeWithStringPath elmCoreAndKernelModuleFilesDefault)
{
static IReadOnlyList<string>? moduleNameFromFileContent(ReadOnlySpan<byte> fileContent)
{
var blobChars = new char[fileContent.Length];

if (!System.Text.Encoding.UTF8.TryGetChars(fileContent, blobChars, out var charsWritten))
return [];

if (ElmSyntax.ElmModule.ParseModuleName(
new string(blobChars.AsSpan()[..charsWritten])).IsOkOrNull() is not { } moduleName)
{
return [];
}

return moduleName;
}

var appCodeTreeModuleNames =
appCodeTree.EnumerateBlobsTransitive()
.SelectMany((blob) =>
{
var fileName = blob.path.Last();

if (!fileName.EndsWith(".elm", StringComparison.OrdinalIgnoreCase))
return (IEnumerable<IReadOnlyList<string>>)[];

if (moduleNameFromFileContent(blob.blobContent.Span) is not { } moduleName)
{
return [];
}

return [moduleName];
})
.ToImmutableHashSet(EnumerableExtension.EqualityComparer<IReadOnlyList<string>>());

return
elmCoreAndKernelModuleFilesDefault
.EnumerateBlobsTransitive()
Expand All @@ -278,11 +312,21 @@ public static TreeNodeWithStringPath MergeDefaultElmCoreAndKernelModules(

func:
(aggregate, nextBlob) =>
aggregate.GetNodeAtPath(nextBlob.path) is { } existingNode
?
aggregate
:
aggregate.SetNodeAtPathSorted(nextBlob.path, TreeNodeWithStringPath.Blob(nextBlob.blobContent)));
{
if (aggregate.GetNodeAtPath(nextBlob.path) is not null)
return aggregate;

if (moduleNameFromFileContent(nextBlob.blobContent.Span) is { } moduleName)
{
if (appCodeTreeModuleNames.Contains(moduleName))
return aggregate;
}

return
aggregate.SetNodeAtPathSorted(
nextBlob.path,
TreeNodeWithStringPath.Blob(nextBlob.blobContent));
});
}

public record ParsedModule(
Expand Down
2 changes: 1 addition & 1 deletion implement/prebuild/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static PineValue BundleElmCompiler()
public static Result<string, PineValue> BuildElmCompilerFirstIteration(
TreeNodeWithStringPath elmCompilerSource)
{
if (false)
if (true)
{
var previousCompiler = LoadPreviousCompiler();

Expand Down

0 comments on commit 9eb31ec

Please sign in to comment.