Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
80ae4e9
[compiler] Foundation of new mutability and aliasing (alternate take)
josephsavona May 22, 2025
6cc2651
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 23, 2025
61bd21c
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 27, 2025
31917eb
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 27, 2025
b72cd79
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 28, 2025
96d33f4
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 28, 2025
5303354
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 29, 2025
402ad86
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 29, 2025
45e14cf
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 30, 2025
8ba9255
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 30, 2025
42d0340
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 30, 2025
8729287
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona May 30, 2025
54b93d9
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 2, 2025
d3e4fbb
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 3, 2025
b4832f2
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 3, 2025
f7e6bad
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 4, 2025
f5515ec
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 4, 2025
402829e
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 5, 2025
e50484e
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 5, 2025
ab402e8
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 5, 2025
c97d6d7
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 6, 2025
b0173de
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 6, 2025
e330119
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 6, 2025
c293b69
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 6, 2025
f5598f4
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 7, 2025
b841803
Update on "[compiler] Foundation of new mutability and aliasing (alte…
josephsavona Jun 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ import {validateNoImpureFunctionsInRender} from '../Validation/ValidateNoImpureF
import {CompilerError} from '..';
import {validateStaticComponents} from '../Validation/ValidateStaticComponents';
import {validateNoFreezingKnownMutableFunctions} from '../Validation/ValidateNoFreezingKnownMutableFunctions';
import {inferMutationAliasingEffects} from '../Inference/InferMutationAliasingEffects';
import {inferMutationAliasingRanges} from '../Inference/InferMutationAliasingRanges';

export type CompilerPipelineValue =
| {kind: 'ast'; name: string; value: CodegenFunction}
Expand Down Expand Up @@ -226,6 +228,16 @@ function runWithEnvironment(
analyseFunctions(hir);
log({kind: 'hir', name: 'AnalyseFunctions', value: hir});

const mutabilityAliasingErrors = inferMutationAliasingEffects(hir);
log({kind: 'hir', name: 'InferMutationAliasingEffects', value: hir});
if (env.isInferredMemoEnabled) {
if (mutabilityAliasingErrors.isErr()) {
throw mutabilityAliasingErrors.unwrapErr();
}
}
inferMutationAliasingRanges(hir);
log({kind: 'hir', name: 'InferMutationAliasingRanges', value: hir});

const fnEffectErrors = inferReferenceEffects(hir);
if (env.isInferredMemoEnabled) {
if (fnEffectErrors.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type ReactiveInstruction = {
id: InstructionId;
lvalue: Place | null;
value: ReactiveValue;
effects?: Array<AliasingEffect> | null; // TODO make non-optional
loc: SourceLocation;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {CompilerError} from '../CompilerError';
import {AliasingSignature} from '../Inference/InferMutationAliasingEffects';
import {Effect, ValueKind, ValueReason} from './HIR';
import {
BuiltInType,
Expand Down Expand Up @@ -179,6 +180,8 @@ export type FunctionSignature = {
impure?: boolean;

canonicalName?: string;

aliasing?: AliasingSignature | null;
};

/*
Expand Down Expand Up @@ -332,6 +335,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
returnValueKind: ValueKind.Mutable,
noAlias: true,
mutableOnlyIfOperandsAreMutable: true,
aliasing: null,
}),
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import type {
Type,
} from './HIR';
import {GotoVariant, InstructionKind} from './HIR';
import {
AliasedPlace,
AliasingEffect,
} from '../Inference/InferMutationAliasingEffects';

export type Options = {
indent: number;
Expand Down Expand Up @@ -151,7 +155,10 @@ export function printMixedHIR(

export function printInstruction(instr: ReactiveInstruction): string {
const id = `[${instr.id}]`;
const value = printInstructionValue(instr.value);
let value = printInstructionValue(instr.value);
if (instr.effects != null) {
value += `\n ${instr.effects.map(printAliasingEffect).join('\n ')}`;
}

if (instr.lvalue !== null) {
return `${id} ${printPlace(instr.lvalue)} = ${value}`;
Expand Down Expand Up @@ -933,3 +940,46 @@ function getFunctionName(
return defaultValue;
}
}

export function printAliasingEffect(effect: AliasingEffect): string {
switch (effect.kind) {
case 'Alias': {
return `Alias ${printPlaceForAliasEffect(effect.from)} -> ${printPlaceForAliasEffect(effect.into)}`;
}
case 'Capture': {
return `Capture ${printPlaceForAliasEffect(effect.from)} -> ${printPlaceForAliasEffect(effect.into)}`;
}
case 'Create': {
return `Create ${printPlaceForAliasEffect(effect.into)} = ${effect.value}`;
}
case 'CreateFrom': {
return `Create ${printPlaceForAliasEffect(effect.into)} = kindOf(${printPlaceForAliasEffect(effect.from)})`;
}
case 'Apply': {
const params = effect.params.map(printAliasedPlace).join(', ');
const rest = effect.rest != null ? printAliasedPlace(effect.rest) : '';
const returns = printAliasedPlace(effect.returns);
return `Apply ${returns} = ${printAliasedPlace(effect.function)} as ${effect.receiver} ( ${params} ${params.length !== 0 && rest !== '' ? ', ...' : ''}${rest})`;
}
case 'Freeze': {
return `Freeze ${printPlaceForAliasEffect(effect.value)} ${effect.reason}`;
}
case 'Mutate':
case 'MutateConditionally':
case 'MutateTransitive':
case 'MutateTransitiveConditionally': {
return `${effect.kind} ${printPlaceForAliasEffect(effect.value)}`;
}
default: {
assertExhaustive(effect, `Unexpected kind '${(effect as any).kind}'`);
}
}
}

function printPlaceForAliasEffect(place: Place): string {
return printIdentifier(place.identifier);
}

function printAliasedPlace(place: AliasedPlace): string {
return place.kind + ' ' + printPlaceForAliasEffect(place.place);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function debugAliases(aliases: DisjointSet<Identifier>): void {
*
* This ensures that we fixpoint the mutable ranges themselves and not just the alias sets.
*/
function canonicalize(
export function canonicalize(
aliases: DisjointSet<Identifier>,
): Map<Identifier, string> {
const entries = new Map<Identifier, string>();
Expand All @@ -132,7 +132,7 @@ function canonicalize(
return entries;
}

function areEqualMaps<T, U>(a: Map<T, U>, b: Map<T, U>): boolean {
export function areEqualMaps<T, U>(a: Map<T, U>, b: Map<T, U>): boolean {
if (a.size !== b.size) {
return false;
}
Expand Down
Loading
Loading