Repository: apple/pkl
File: pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java (Java)

Code before:
    public VmTyped getMirror() {
      return MirrorFactories.typeAliasTypeFactory.create(this);
    }

    @Override
    public VmList getTypeArgumentMirrors() {
      return getMirrors(typeArgumentNodes);
    }

    public void execute(VirtualFrame frame, Object value) {
      aliasedTypeNode.execute(frame, value);
    }

    @Override
    public void executeAndSet(VirtualFrame frame, Object value) {
      aliasedTypeNode.executeAndSet(frame, value);
    }

    @Override
    @TruffleBoundary
    public @Nullable Object createDefaultValue(
        VmLanguage language, SourceSection headerSection, String qualifiedName) {

      if (typeAlias == BaseModule.getMixinTypeAlias()) {
        //noinspection ConstantConditions
        return new VmFunction(
            VmUtils.createEmptyMaterializedFrame(),
            // Assumption: don't need to set the correct `thisValue`
            // because it is guaranteed to be never accessed.
            null,
            1,
            new IdentityMixinNode(
                language,
                new FrameDescriptor(),
                getSourceSection(),
                qualifiedName,
                typeArgumentNodes.length == 1
                    ?
                    // shouldn't need to deepCopy() this node because it isn't used as @Child
                    // anywhere else
                    typeArgumentNodes[0]
                    : null),
            null);
      }

      return aliasedTypeNode.createDefaultValue(language, headerSection, qualifiedName);
    }

    @Override
    public @Nullable VmClass getVmClass() {
      return aliasedTypeNode.getVmClass();

Review comment (suggestion):
Let's avoid allocating a `Map.Entry` and do:

```suggestion
    public void execute(VirtualFrame frame, Object value) {
      var prevOwner = VmUtils.getOwner(frame);
      var prevReceiver = VmUtils.getReceiver(frame);
      VmUtils.setOwner(frame, VmUtils.getOwner(typeAlias.getEnclosingFrame()));
      VmUtils.setReceiver(frame, VmUtils.getReceiver(typeAlias.getEnclosingFrame()));

      aliasedTypeNode.execute(frame, value);

      VmUtils.setOwner(frame, prevOwner);
      VmUtils.setReceiver(frame, prevReceiver);
    }
```

Same with the other method

Code after:
    public VmTyped getMirror() {
      return MirrorFactories.typeAliasTypeFactory.create(this);
    }

    @Override
    public VmList getTypeArgumentMirrors() {
      return getMirrors(typeArgumentNodes);
    }

    /**
     * A typealias body is effectively inlined into the type node, and not executed in its own
     * frame.
     *
     * <p>Before executing the typealias body, use the owner and receiver of the original frame
     * where the typealias was declared, so that we preserve its original scope.
     */
    public void execute(VirtualFrame frame, Object value) {
      var prevOwner = VmUtils.getOwner(frame);
      var prevReceiver = VmUtils.getReceiver(frame);
      VmUtils.setOwner(frame, VmUtils.getOwner(typeAlias.getEnclosingFrame()));
      VmUtils.setReceiver(frame, VmUtils.getReceiver(typeAlias.getEnclosingFrame()));

      aliasedTypeNode.execute(frame, value);
      VmUtils.setOwner(frame, prevOwner);
      VmUtils.setReceiver(frame, prevReceiver);
    }

    /** See docstring on {@link TypeAliasTypeNode#execute}. */
    @Override
    public void executeAndSet(VirtualFrame frame, Object value) {
      var prevOwner = VmUtils.getOwner(frame);
      var prevReceiver = VmUtils.getReceiver(frame);
      VmUtils.setOwner(frame, VmUtils.getOwner(typeAlias.getEnclosingFrame()));
      VmUtils.setReceiver(frame, VmUtils.getReceiver(typeAlias.getEnclosingFrame()));

      aliasedTypeNode.executeAndSet(frame, value);

      VmUtils.setOwner(frame, prevOwner);
      VmUtils.setReceiver(frame, prevReceiver);
    }

    @Override
    @TruffleBoundary
    public @Nullable Object createDefaultValue(
        VmLanguage language, SourceSection headerSection, String qualifiedName) {

      if (typeAlias == BaseModule.getMixinTypeAlias()) {
        //noinspection ConstantConditions
        return new VmFunction(
            VmUtils.createEmptyMaterializedFrame(),
            // Assumption: don't need to set the correct `thisValue`