Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
[hir] Remove unused code from InferAlias
Browse files Browse the repository at this point in the history
For now, we've decided to punt on super fine grained aliasing of fields (ie, 
mutating x.y shouldn't mutate x.z or it's aliases). 

This PR removes the code that tracks the aliases of each field. We can re-add 
this when we revisit this functionality. 

For the rest of the field aliasing, most of it has been replaced by 
InferAliasForStores.
  • Loading branch information
gsathya authored and pull[bot] committed Jun 12, 2024
1 parent c7cb30d commit fb0f208
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions compiler/forget/src/HIR/InferAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,13 @@ export type AliasSet = Set<Identifier>;

class AliasAnalyser {
aliases = new DisjointSet<Identifier>();
// NOTE(gsn): Should this be a part of AbstractObject? No, because this has
// nothing to do with values in the object.
objectAliases = new Map<Identifier, Map<string, AliasSet>>();

alias(lvalue: LValue, alias: Place) {
// Complex lvalue:
// lvalue.memberPath = alias;
// lvalue.memberPath = alias.someMemberPath;
// This is handled by InferAliasForStores.
if (lvalue.place.memberPath !== null) {
// TODO(gsn): Handle nested memberPaths in lvalue.
if (lvalue.place.memberPath.length > 1) {
return;
}
let memberPath = lvalue.place.memberPath[0];

// Consider the case of:
// lvalue.memberPath = alias;
// mutate(lvalue); <-- `alias` should be considered mutable
// here.
//
// Similarly for this case,
// mutate(lvalue.memberPath); <-- `alias` should be considered mutable
// here as well.
//
// But what about this case:
// mutate(lvalue.foo); <-- Do we consider `alias` mutable here?
// No!
//
// To distinguish between these different cases, we need to build separate
// alias sets for each memberPath of `lvalue`.
let objectAlias = this.objectAliases.get(lvalue.place.identifier);
if (objectAlias === undefined) {
objectAlias = new Map<string, AliasSet>();
this.objectAliases.set(lvalue.place.identifier, objectAlias);
}

let memberAlias = objectAlias.get(memberPath);
if (memberAlias === undefined) {
memberAlias = new Set<Identifier>();
objectAlias.set(memberPath, memberAlias);
}

memberAlias.add(alias.identifier);
return;
}

// Simple lvalue:
// lvalue = alias;
// lvalue = alias.memberPath;
this.aliases.union([lvalue.place.identifier, alias.identifier]);
}
}
Expand Down Expand Up @@ -81,12 +39,9 @@ function inferInstr(instr: Instruction, state: AliasAnalyser) {
return;
}

// TODO(gsn): handle this.
if (lvalue === null) {
return;
}

if (alias !== null) {
state.alias(lvalue, alias);
}
state.alias(lvalue, alias);
}

0 comments on commit fb0f208

Please sign in to comment.