-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New IR -- WIP #24466
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
base: master
Are you sure you want to change the base?
New IR -- WIP #24466
Conversation
ed4c70f
to
6ea030e
Compare
example assembly printout
|
30ed4b3
to
852f33b
Compare
d71a5b9
to
8f19d4a
Compare
27649af
to
40aeed5
Compare
{ | ||
public OperationNode(Optional<String> dialect, String name, String resultName, TypeNode resultType, List<String> argumentNames, List<TypeNode> argumentTypes, List<RegionNode> regions, List<AttributeNode> attributes) | ||
{ | ||
requireNonNull(dialect, "dialect is null"); | ||
requireNonNull(name, "name is null"); | ||
requireNonNull(resultName, "resultName is null"); | ||
requireNonNull(resultType, "resultType is null"); | ||
requireNonNull(argumentNames, "argumentNames is null"); | ||
requireNonNull(argumentTypes, "argumentTypes is null"); | ||
requireNonNull(regions, "regions is null"); | ||
requireNonNull(attributes, "attributes is null"); | ||
|
||
checkArgument(argumentNames.size() == argumentTypes.size(), "argument names and argument types lists do not match in size"); | ||
|
||
this.dialect = dialect; | ||
this.name = name; | ||
this.resultName = resultName; | ||
this.resultType = resultType; | ||
this.argumentNames = ImmutableList.copyOf(argumentNames); | ||
this.argumentTypes = ImmutableList.copyOf(argumentTypes); | ||
this.regions = ImmutableList.copyOf(regions); | ||
this.attributes = ImmutableList.copyOf(attributes); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | |
public OperationNode(Optional<String> dialect, String name, String resultName, TypeNode resultType, List<String> argumentNames, List<TypeNode> argumentTypes, List<RegionNode> regions, List<AttributeNode> attributes) | |
{ | |
requireNonNull(dialect, "dialect is null"); | |
requireNonNull(name, "name is null"); | |
requireNonNull(resultName, "resultName is null"); | |
requireNonNull(resultType, "resultType is null"); | |
requireNonNull(argumentNames, "argumentNames is null"); | |
requireNonNull(argumentTypes, "argumentTypes is null"); | |
requireNonNull(regions, "regions is null"); | |
requireNonNull(attributes, "attributes is null"); | |
checkArgument(argumentNames.size() == argumentTypes.size(), "argument names and argument types lists do not match in size"); | |
this.dialect = dialect; | |
this.name = name; | |
this.resultName = resultName; | |
this.resultType = resultType; | |
this.argumentNames = ImmutableList.copyOf(argumentNames); | |
this.argumentTypes = ImmutableList.copyOf(argumentTypes); | |
this.regions = ImmutableList.copyOf(regions); | |
this.attributes = ImmutableList.copyOf(attributes); | |
} | |
{ | |
public OperationNode | |
{ | |
requireNonNull(dialect, "dialect is null"); | |
requireNonNull(name, "name is null"); | |
requireNonNull(resultName, "resultName is null"); | |
requireNonNull(resultType, "resultType is null"); | |
requireNonNull(argumentNames, "argumentNames is null"); | |
requireNonNull(argumentTypes, "argumentTypes is null"); | |
requireNonNull(regions, "regions is null"); | |
requireNonNull(attributes, "attributes is null"); | |
checkArgument(argumentNames.size() == argumentTypes.size(), "argument names and argument types lists do not match in size"); | |
argumentNames = ImmutableList.copyOf(argumentNames); | |
argumentTypes = ImmutableList.copyOf(argumentTypes); | |
regions = ImmutableList.copyOf(regions); | |
attributes = ImmutableList.copyOf(attributes); | |
} | |
} |
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public record AttributeNode(Optional<String> dialect, String name, String attribute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String value
import static com.google.common.base.Preconditions.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public record BlockNode(Optional<String> name, List<String> parameterNames, List<TypeNode> parameterTypes, List<OperationNode> operations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of two parallel lists (parameterNames and parameterTypes), use a single list of a composite object type (e.g., Parameter) that contains a name and a type
import static com.google.common.base.Preconditions.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public record OperationNode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flattening everything makes it harder to understand the relationship between the elements. I would structure it such that the operation has:
- a dialect
- a name
- a list of arguments
- an operation type (which in turn, has a result type and argument types)
- a list of regions
- a list of attributes
Also, we may need to model assignments as an element enclosing an operation, since not all callsites may need to be assigned. I.e., something like:
assignment ::= name '=' operation
|
||
static void validateValueName(String name) | ||
{ | ||
if (!name.startsWith("%") || !isValidPrefixedIdentifier(name.substring(1))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The '%' prefix should only exist at parsing and printing time, but should not be carried over in the name of the variable.
public class FormatOptions | ||
{ | ||
public static final String INDENT = " "; | ||
private static final Pattern IDENTIFIER = Pattern.compile("([a-z]|[A-Z]|_)([a-z]|[A-Z]|[0-9]|_)*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[a-z]|[A-Z]|[0-9]|_
can be simplified to [a-zA-Z0-9_]
private final List<Value> inputList; | ||
private final Map<AttributeKey, Object> attributes; | ||
|
||
public In(String resultName, Value input, List<Value> inputList, List<Map<AttributeKey, Object>> sourceAttributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input list should modeled as a single value of type "array"
public Context(Block.Builder block, Map<Symbol, RowField> symbolMapping) | ||
{ | ||
this.block = requireNonNull(block, "block is null"); | ||
this.symbolMapping = ImmutableMap.copyOf(requireNonNull(symbolMapping, "symbolMapping is null")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requireNonNull not needed
public Operation getOperation(Result value) | ||
{ | ||
SourceNode source = valueMap.get(value); | ||
if (source == null) { | ||
throw new TrinoException(IR_ERROR, format("value %s is not defined", value.name())); | ||
} | ||
|
||
if (source instanceof Operation operation) { | ||
if (!value.type().equals(operation.result().type())) { | ||
throw new TrinoException(IR_ERROR, format("value %s type mismatch. expected: %s, actual: %s", value.name(), value.type(), operation.result().type())); | ||
} | ||
return operation; | ||
} | ||
|
||
throw new TrinoException(IR_ERROR, format("value %s is not an operation result", value.name())); | ||
} | ||
|
||
public Block getBlock(Parameter value) | ||
{ | ||
SourceNode source = valueMap.get(value); | ||
if (source == null) { | ||
throw new TrinoException(IR_ERROR, format("value %s is not defined", value.name())); | ||
} | ||
|
||
if (source instanceof Block block) { | ||
Type parameterType = block.parameters().get(block.getIndex(value)).type(); | ||
if (!value.type().equals(parameterType)) { | ||
throw new TrinoException(IR_ERROR, format("value %s type mismatch. expected: %s, actual: %s", value.name(), value.type(), parameterType)); | ||
} | ||
return block; | ||
} | ||
|
||
throw new TrinoException(IR_ERROR, format("value %s is not a block parameter", value.name())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods aren't used anywhere. What's the use case for them?
6a1228b
to
3fb3ccd
Compare
d53a39e
to
6c59149
Compare
227b659
to
909c600
Compare
b8e5df6
to
eeb711c
Compare
eeb711c
to
c0ab3dc
Compare
This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack. |
See core/trino-main/src/main/java/io/trino/sql/newir/README.md for details.