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

Prune assumptions #915

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c47a05
Some good results with the prototype
keyboardDrummer Jul 19, 2024
bd1e255
Add block optimizations
keyboardDrummer Jul 19, 2024
a83c8fb
Make printing reliable
keyboardDrummer Jul 19, 2024
a8af071
Remove obsolete comment
keyboardDrummer Jul 19, 2024
edc7885
Refactor printing code
keyboardDrummer Jul 19, 2024
0a04ac2
Further printing refactoring
keyboardDrummer Jul 19, 2024
24e80ae
Do not introduce empty splits
keyboardDrummer Jul 19, 2024
206d6cd
Refactoring
keyboardDrummer Jul 19, 2024
dd24bad
Refactoring
keyboardDrummer Jul 19, 2024
a96f08a
Update split printing
keyboardDrummer Jul 19, 2024
ebad173
Some fixes
keyboardDrummer Jul 19, 2024
6d31655
Laziness in block optimization
keyboardDrummer Jul 22, 2024
bc8c963
Merge remote-tracking branch 'origin/master' into pruneAssumptions
keyboardDrummer Jul 22, 2024
5dd99eb
Removed unused branch
keyboardDrummer Jul 22, 2024
c610cc0
Fixes
keyboardDrummer Jul 22, 2024
adf9514
Fix and reaches analysis
keyboardDrummer Jul 22, 2024
6bad09b
Change live analysis
keyboardDrummer Jul 22, 2024
91f8553
Algoritm update
keyboardDrummer Jul 22, 2024
9dbeec2
Some hacks to make it work
keyboardDrummer Jul 23, 2024
152e4cd
Fixes
keyboardDrummer Jul 23, 2024
841b040
Fixes
keyboardDrummer Jul 23, 2024
acde618
Fix
keyboardDrummer Jul 23, 2024
96fdae8
Tweak
keyboardDrummer Jul 23, 2024
1e03e89
Use globals vs locals idea. 3855 is still failing
keyboardDrummer Jul 24, 2024
97fbea5
3855 passes now
keyboardDrummer Jul 24, 2024
3bfc33d
Useless update
keyboardDrummer Jul 24, 2024
2b174b5
Tiny change
keyboardDrummer Jul 24, 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
1,075 changes: 0 additions & 1,075 deletions Source/Core/AST/Absy.cs

Large diffs are not rendered by default.

226 changes: 6 additions & 220 deletions Source/Core/AST/AbsyCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,225 +1189,6 @@ public override void Emit(TokenTextWriter stream, int level)

//---------------------------------------------------------------------
// Block
public sealed class Block : Absy
{
private string /*!*/ label; // Note, Label is mostly readonly, but it can change to the name of a nearby block during block coalescing and empty-block removal

public string /*!*/ Label
{
get
{
Contract.Ensures(Contract.Result<string>() != null);
return this.label;
}
set
{
Contract.Requires(value != null);
this.label = value;
}
}

[Rep] [ElementsPeer] public List<Cmd> /*!*/ cmds;

public List<Cmd> /*!*/ Cmds
{
get
{
Contract.Ensures(Contract.Result<List<Cmd>>() != null);
return this.cmds;
}
set
{
Contract.Requires(value != null);
this.cmds = value;
}
}

public IEnumerable<Block> Exits()
{
if (TransferCmd is GotoCmd g)
{
return cce.NonNull(g.labelTargets);
}
return new List<Block>();
}

[Rep] //PM: needed to verify Traverse.Visit
public TransferCmd
TransferCmd; // maybe null only because we allow deferred initialization (necessary for cyclic structures)

public byte[] Checksum;

// Abstract interpretation

// public bool currentlyTraversed;

public enum VisitState
{
ToVisit,
BeingVisited,
AlreadyVisited
} // used by WidenPoints.Compute

public VisitState TraversingStatus;

public int aiId; // block ID used by the abstract interpreter, which may change these numbers with each AI run
public bool widenBlock;

public int
iterations; // Count the number of time we visited the block during fixpoint computation. Used to decide if we widen or not

// VC generation and SCC computation
public List<Block> /*!*/ Predecessors;

// This field is used during passification to null-out entries in block2Incarnation dictionary early
public int succCount;

private HashSet<Variable /*!*/> _liveVarsBefore;

public IEnumerable<Variable /*!*/> liveVarsBefore
{
get
{
Contract.Ensures(cce.NonNullElements(Contract.Result<IEnumerable<Variable /*!*/>>(), true));
if (this._liveVarsBefore == null)
{
return null;
}
else
{
return this._liveVarsBefore.AsEnumerable<Variable>();
}
}
set
{
Contract.Requires(cce.NonNullElements(value, true));
if (value == null)
{
this._liveVarsBefore = null;
}
else
{
this._liveVarsBefore = new HashSet<Variable>(value);
}
}
}

[ContractInvariantMethod]
void ObjectInvariant()
{
Contract.Invariant(this.label != null);
Contract.Invariant(this.cmds != null);
Contract.Invariant(cce.NonNullElements(this._liveVarsBefore, true));
}

public bool IsLive(Variable v)
{
Contract.Requires(v != null);
if (liveVarsBefore == null)
{
return true;
}

return liveVarsBefore.Contains(v);
}

public Block()
: this(Token.NoToken, "", new List<Cmd>(), new ReturnCmd(Token.NoToken))
{
}

public Block(IToken tok, string /*!*/ label, List<Cmd> /*!*/ cmds, TransferCmd transferCmd)
: base(tok)
{
Contract.Requires(label != null);
Contract.Requires(cmds != null);
Contract.Requires(tok != null);
this.label = label;
this.cmds = cmds;
this.TransferCmd = transferCmd;
this.Predecessors = new List<Block>();
this._liveVarsBefore = null;
this.TraversingStatus = VisitState.ToVisit;
this.iterations = 0;
}

public void Emit(TokenTextWriter stream, int level)
{
Contract.Requires(stream != null);
stream.WriteLine();
stream.WriteLine(
this,
level,
"{0}:{1}",
stream.Options.PrintWithUniqueASTIds
? String.Format("h{0}^^{1}", this.GetHashCode(), this.Label)
: this.Label,
this.widenBlock ? " // cut point" : "");

foreach (Cmd /*!*/ c in this.Cmds)
{
Contract.Assert(c != null);
c.Emit(stream, level + 1);
}

Contract.Assume(this.TransferCmd != null);
this.TransferCmd.Emit(stream, level + 1);
}

public void Register(ResolutionContext rc)
{
Contract.Requires(rc != null);
rc.AddBlock(this);
}

public override void Resolve(ResolutionContext rc)
{
foreach (Cmd /*!*/ c in Cmds)
{
Contract.Assert(c != null);
c.Resolve(rc);
}

Contract.Assume(this.TransferCmd != null);
TransferCmd.Resolve(rc);
}

public override void Typecheck(TypecheckingContext tc)
{
foreach (Cmd /*!*/ c in Cmds)
{
Contract.Assert(c != null);
c.Typecheck(tc);
}

Contract.Assume(this.TransferCmd != null);
TransferCmd.Typecheck(tc);
}

/// <summary>
/// Reset the abstract intepretation state of this block. It does this by putting the iterations to 0 and the pre and post states to null
/// </summary>
public void ResetAbstractInterpretationState()
{
// this.currentlyTraversed = false;
this.TraversingStatus = VisitState.ToVisit;
this.iterations = 0;
}

[Pure]
public override string ToString()
{
Contract.Ensures(Contract.Result<string>() != null);
return this.Label + (this.widenBlock ? "[w]" : "");
}

public override Absy StdDispatch(StandardVisitor visitor)
{
Contract.Ensures(Contract.Result<Absy>() != null);
return visitor.VisitBlock(this);
}
}

//---------------------------------------------------------------------
// Commands
Expand Down Expand Up @@ -3716,7 +3497,7 @@ void ObjectInvariant()
{
Contract.Invariant(labelNames == null || labelTargets == null || labelNames.Count == labelTargets.Count);
}

[NotDelayed]
public GotoCmd(IToken /*!*/ tok, List<String> /*!*/ labelSeq)
: base(tok)
Expand Down Expand Up @@ -3758,6 +3539,11 @@ public GotoCmd(IToken /*!*/ tok, List<Block> /*!*/ blockSeq)
this.labelTargets = blockSeq;
}

public void RemoveTarget(Block b) {
labelNames.Remove(b.Label);
labelTargets.Remove(b);
}

public void AddTarget(Block b)
{
Contract.Requires(b != null);
Expand Down
Loading