Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Rename idOrPath to astRef and add explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed May 22, 2020
1 parent ca01e1c commit 8c41e9b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 50 deletions.
6 changes: 3 additions & 3 deletions packages/debugger/lib/data/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export function scope(id, pointer, parentId, sourceId, compilationId) {
}

export const DECLARE = "DATA_DECLARE_VARIABLE";
export function declare(name, idOrPath, scopeIdOrPath, compilationId) {
export function declare(name, astRef, scopeAstRef, compilationId) {
return {
type: DECLARE,
name,
idOrPath,
scopeIdOrPath,
astRef,
scopeAstRef,
compilationId
};
}
Expand Down
39 changes: 21 additions & 18 deletions packages/debugger/lib/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ function scopes(state = DEFAULT_SCOPES, action) {
switch (action.type) {
case actions.SCOPE: {
const { compilationId, id, sourceId, parentId, pointer } = action;
const idOrPath = id !== undefined ? id : makePath(sourceId, pointer);
const astRef = id !== undefined ? id : makePath(sourceId, pointer);
//astRef is used throughout the data saga.
//it identifies an AST node within a given compilation either by:
//1. its ast ID, if it has one, or
//2. a combination of its source index and its JSON pointer if not

newState = {
byCompilationId: {
Expand All @@ -35,14 +39,14 @@ function scopes(state = DEFAULT_SCOPES, action) {

newState.byCompilationId[compilationId] = {
...newState.byCompilationId[compilationId],
byIdOrPath: {
...newState.byCompilationId[compilationId].byIdOrPath
byAstRef: {
...newState.byCompilationId[compilationId].byAstRef
}
};

scope = newState.byCompilationId[compilationId].byIdOrPath[idOrPath];
scope = newState.byCompilationId[compilationId].byAstRef[astRef];

newState.byCompilationId[compilationId].byIdOrPath[idOrPath] = {
newState.byCompilationId[compilationId].byAstRef[astRef] = {
...scope,
id,
sourceId,
Expand All @@ -55,30 +59,29 @@ function scopes(state = DEFAULT_SCOPES, action) {
}

case actions.DECLARE: {
let { compilationId, name, idOrPath, scopeIdOrPath } = action;
let { compilationId, name, astRef, scopeAstRef } = action;

//note: we can assume the compilation already exists!
scope =
state.byCompilationId[compilationId].byIdOrPath[scopeIdOrPath] || {};
scope = state.byCompilationId[compilationId].byAstRef[scopeAstRef] || {};
variables = scope.variables || [];

return {
byCompilationId: {
...state.byCompilationId,
[compilationId]: {
...state.byCompilationId[compilationId],
byIdOrPath: {
...state.byCompilationId[compilationId].byIdOrPath,
byAstRef: {
...state.byCompilationId[compilationId].byAstRef,

[scopeIdOrPath]: {
[scopeAstRef]: {
...scope,

variables: [
...variables,

{
name,
idOrPath,
astRef,
compilationId
}
]
Expand Down Expand Up @@ -169,7 +172,7 @@ function assignments(state = DEFAULT_ASSIGNMENTS, action) {
debug("action.type %O", action.type);
debug("action.assignments %O", action.assignments);
return Object.values(action.assignments).reduce((acc, assignment) => {
let { id, idOrPath, compilationId } = assignment;
let { id, astRef, compilationId } = assignment;
//we assume for now that only ordinary variables will be assigned this
//way, and not globals; globals are handled in DEFAULT_ASSIGNMENTS
return {
Expand All @@ -182,12 +185,12 @@ function assignments(state = DEFAULT_ASSIGNMENTS, action) {
...acc.byCompilationId,
[compilationId]: {
...acc.byCompilationId[compilationId],
byIdOrPath: {
...(acc.byCompilationId[compilationId] || {}).byIdOrPath,
[idOrPath]: [
byAstRef: {
...(acc.byCompilationId[compilationId] || {}).byAstRef,
[astRef]: [
...new Set([
...(((acc.byCompilationId[compilationId] || {})
.byIdOrPath || {})[idOrPath] || []),
...(((acc.byCompilationId[compilationId] || {}).byAstRef ||
{})[astRef] || []),
id
])
]
Expand Down
30 changes: 15 additions & 15 deletions packages/debugger/lib/data/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ function* variablesAndMappingsSaga() {
inModifier
? {
compilationId,
idOrPath: sourceAndPointer,
astRef: sourceAndPointer,
stackframe: currentDepth,
modifierDepth
}
: {
compilationId,
idOrPath: sourceAndPointer,
astRef: sourceAndPointer,
stackframe: currentDepth
},
{
Expand All @@ -412,7 +412,7 @@ function* variablesAndMappingsSaga() {
assignments = {};
for (let id in allocation.members) {
id = Number(id); //not sure why we're getting them as strings, but...
let idObj = { compilationId, idOrPath: id, address };
let idObj = { compilationId, astRef: id, address };
let fullId = stableKeccak256(idObj);
//we don't use makeAssignment here as we had to compute the ID anyway
assignment = {
Expand Down Expand Up @@ -461,11 +461,11 @@ function* variablesAndMappingsSaga() {
inModifier
? {
compilationId,
idOrPath: varId,
astRef: varId,
stackframe: currentDepth,
modifierDepth
}
: { compilationId, idOrPath: varId, stackframe: currentDepth },
: { compilationId, astRef: varId, stackframe: currentDepth },
{
location: "stack",
from: top - Codec.Ast.Utils.stackSize(node) + 1,
Expand Down Expand Up @@ -512,13 +512,13 @@ function* variablesAndMappingsSaga() {
inModifier
? {
compilationId,
idOrPath: variableSourceAndPointer,
astRef: variableSourceAndPointer,
stackframe: currentDepth,
modifierDepth
}
: {
compilationId,
idOrPath: variableSourceAndPointer,
astRef: variableSourceAndPointer,
stackframe: currentDepth
},
{
Expand Down Expand Up @@ -785,11 +785,11 @@ function* decodeMappingKeyCore(indexDefinition, keyDefinition) {
let indexIdObj = inModifier
? {
compilationId,
idOrPath: indexId,
astRef: indexId,
stackframe: currentDepth,
modifierDepth
}
: { compilationId, idOrPath: indexId, stackframe: currentDepth };
: { compilationId, astRef: indexId, stackframe: currentDepth };
let fullIndexId = stableKeccak256(indexIdObj);

const indexReference = (currentAssignments.byId[fullIndexId] || {}).ref;
Expand Down Expand Up @@ -971,11 +971,11 @@ function literalAssignments(
inModifier
? {
compilationId,
idOrPath: node.id,
astRef: node.id,
stackframe: currentDepth,
modifierDepth
}
: { compilationId, idOrPath: node.id, stackframe: currentDepth },
: { compilationId, astRef: node.id, stackframe: currentDepth },
{ location: "stackliteral", literal }
);

Expand Down Expand Up @@ -1009,11 +1009,11 @@ function assignParameters(
forModifier
? {
compilationId,
idOrPath: parameter.id,
astRef: parameter.id,
stackframe: functionDepth,
modifierDepth
}
: { compilationId, idOrPath: parameter.id, stackframe: functionDepth },
: { compilationId, astRef: parameter.id, stackframe: functionDepth },
pointer
);
assignments[assignment.id] = assignment;
Expand All @@ -1035,13 +1035,13 @@ function fetchBasePath(
inModifier
? {
compilationId,
idOrPath: baseNode.id,
astRef: baseNode.id,
stackframe: currentDepth,
modifierDepth
}
: {
compilationId,
idOrPath: baseNode.id,
astRef: baseNode.id,
stackframe: currentDepth
}
);
Expand Down
28 changes: 14 additions & 14 deletions packages/debugger/lib/data/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const data = createSelectorTree({
)
.filter(
variable =>
inlined[compilationId][variable.idOrPath].definition
inlined[compilationId][variable.astRef].definition
.visibility !== "private"
//filter out private variables from the base classes
)
Expand All @@ -236,7 +236,7 @@ const data = createSelectorTree({
//how to read. they'll just clutter things up.
debug("variable %O", variable);
let definition =
inlined[compilationId][variable.idOrPath].definition;
inlined[compilationId][variable.astRef].definition;
return (
!definition.constant ||
Codec.Ast.Utils.isSimpleConstant(definition.value)
Expand All @@ -261,7 +261,7 @@ const data = createSelectorTree({
Object.assign(
{},
...Object.entries(scopes.byCompilationId).map(
([compilationId, { byIdOrPath: nodes }]) => ({
([compilationId, { byAstRef: nodes }]) => ({
[compilationId]: { ...nodes }
})
)
Expand Down Expand Up @@ -1059,7 +1059,7 @@ const data = createSelectorTree({
* data.current.identifiers (selector)
*
* returns identifers and corresponding definition node ID or builtin name
* (object entries look like [name]: {idOrPath: idOrPath}, [name]: {builtin: name})
* (object entries look like [name]: {astRef: astRef}, [name]: {builtin: name})
*/
_: createLeaf(
[
Expand All @@ -1082,7 +1082,7 @@ const data = createSelectorTree({
.filter(variable => variable.name !== "") //exclude anonymous output params
.filter(variable => variables[variable.name] == undefined) //don't add shadowed vars
.map(variable => ({
[variable.name]: { idOrPath: variable.idOrPath }
[variable.name]: { astRef: variable.astRef }
}))
);
//NOTE: because these assignments are processed in order, that means
Expand Down Expand Up @@ -1141,8 +1141,8 @@ const data = createSelectorTree({
let variables = Object.assign(
{},
...Object.entries(identifiers).map(([identifier, variable]) => {
if (variable.idOrPath !== undefined) {
let { definition } = scopes[variable.idOrPath];
if (variable.astRef !== undefined) {
let { definition } = scopes[variable.astRef];
return { [identifier]: definition };
//there used to be separate code for Yul variables here,
//but now that's handled in definitionToType
Expand Down Expand Up @@ -1211,18 +1211,18 @@ const data = createSelectorTree({
Object.assign(
{},
...Object.entries(identifiers).map(
([identifier, { idOrPath, builtin }]) => {
([identifier, { astRef, builtin }]) => {
let id;
debug("idOrPath: %o", idOrPath);
debug("astRef: %o", astRef);
debug("builtin: %s", builtin);

//is this an ordinary variable or a builtin?
if (idOrPath !== undefined) {
if (astRef !== undefined) {
//if not a builtin, first check if it's a contract var
let compilationAssignments =
(assignments.byCompilationId[compilationId] || {})
.byIdOrPath || {};
id = (compilationAssignments[idOrPath] || []).find(
.byAstRef || {};
id = (compilationAssignments[astRef] || []).find(
idHash => assignments.byId[idHash].address === address
);
debug("id after global: %s", id);
Expand All @@ -1232,14 +1232,14 @@ const data = createSelectorTree({
//if we're in a modifier, include modifierDepth
if (inModifier) {
id = stableKeccak256({
idOrPath,
astRef,
compilationId,
stackframe: currentDepth,
modifierDepth
});
} else {
id = stableKeccak256({
idOrPath,
astRef,
compilationId,
stackframe: currentDepth
});
Expand Down

0 comments on commit 8c41e9b

Please sign in to comment.