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

Code before:
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pkl.core.ast.member;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.ConstantNode;
import org.pkl.core.ast.MemberNode;
import org.pkl.core.ast.VmModifier;
import org.pkl.core.runtime.Identifier;
import org.pkl.core.runtime.VmDynamic;
import org.pkl.core.runtime.VmUtils;
import org.pkl.core.util.Nullable;

public final class ObjectMember extends Member {

  private final boolean isInIterable;

  @CompilationFinal private @Nullable Object constantValue;
  @CompilationFinal private @Nullable MemberNode memberNode;

  public ObjectMember(
      SourceSection sourceSection,
      SourceSection headerSection,
      int modifiers,
      @Nullable Identifier name,
      String qualifiedName,
      boolean isInIterable) {

    super(sourceSection, headerSection, modifiers, name, qualifiedName);
    this.isInIterable = isInIterable;
  }

  public void initConstantValue(ConstantNode node) {
    initConstantValue(node.getValue());
  }

  public void initConstantValue(Object value) {
    assert constantValue == null;
    assert memberNode == null;

    constantValue = value;

Review comment (suggestion):
Seems costly... not worth rolling it into the member's `modifiers`? Probably worth profiling (both `jpkl` and native) on large corpora.

Code after:
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pkl.core.ast.member;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.ConstantNode;
import org.pkl.core.ast.MemberNode;
import org.pkl.core.ast.VmModifier;
import org.pkl.core.runtime.Identifier;
import org.pkl.core.runtime.VmDynamic;
import org.pkl.core.runtime.VmUtils;
import org.pkl.core.util.Nullable;

public final class ObjectMember extends Member {

  @CompilationFinal private @Nullable Object constantValue;
  @CompilationFinal private @Nullable MemberNode memberNode;

  public ObjectMember(
      SourceSection sourceSection,
      SourceSection headerSection,
      int modifiers,
      @Nullable Identifier name,
      String qualifiedName) {

    super(sourceSection, headerSection, modifiers, name, qualifiedName);
  }

  public void initConstantValue(ConstantNode node) {
    initConstantValue(node.getValue());
  }

  public void initConstantValue(Object value) {
    assert constantValue == null;
    assert memberNode == null;

    constantValue = value;
  }

  public void initMemberNode(MemberNode node) {
    assert constantValue == null;