carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Explorer: change `InstantiateType` to be an `Action` instead of a method

Open Pixep opened this issue 2 years ago • 18 comments

Background

Our current explorer implementation uses a simple function for type instantiation (substitute placeholder type with actual types). A better approach would be to have it be an Action for the action stack.

Goal

InstantiateType replaces all type variables (for example T) by their actual type values (for example i32). The goal is to create a new TypeInstantiationAction (class TypeInstantiationAction : public Action) that produces the same behavior.

The InstantiateType method is declared in interpreter.cpp:139

  // Instantiate a type by replacing all type variables that occur inside the
  // type by the current values of those variables.
  //
  // For example, suppose T=i32 and U=bool. Then
  //     __Fn (Point(T)) -> Point(U)
  // becomes
  //     __Fn (Point(i32)) -> Point(bool)
  //
  // TODO: This should be an Action.
  auto InstantiateType(Nonnull<const Value*> type, SourceLocation source_loc)
      -> ErrorOr<Nonnull<const Value*>>;

Suggested approach

At a high-level, this could be achieved by:

  1. Adding a new TypeInstantiationAction enum to Action::Kind
  2. Creating a new TypeInstantiationAction class, following the example of similar classes like ExpressionAction
  3. Updating code that makes use of Actions:
    • Interpreter::Step: entry point of actions, to invoke InstantiateType method
    • Action::Print: prints an action
  4. Changing code that directly invokes InstantiateType, to instead spawn a new TypeInstantiationAction
    • For example: return todo_.Spawn(std::make_unique<TypeInstantiationAction>(...));
    • This will require using act.pos() to add a new step for instantiation, before dependent code can be executed. See Interpreter readme for a description of the action stack

Resources

  • https://github.com/carbon-language/carbon-lang/blob/trunk/CONTRIBUTING.md
  • https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/contribution_tools.md
  • #contributing-help channel on the Discord

Pixep avatar Feb 09 '23 04:02 Pixep

Hi. I'd like to work on this issue

PaarthAgarwal avatar Feb 22 '23 15:02 PaarthAgarwal

Hi. I would like to work on this and I would like to contribute to Carbon Language

varmacolab avatar Feb 23 '23 12:02 varmacolab

Hey @Pixep sir, I would like to contribute to this issue. Could you please assign this to me?

annihilatorBTY avatar Feb 25 '23 04:02 annihilatorBTY

Hi, I'm just starting out with contributions. I found this issue tagged as Good First and I would like to know more about this issue and contribute to Carbon Language. Also, it would be great if I get to know a bit about the prerequisites.

Rohan1Saluja avatar Feb 25 '23 09:02 Rohan1Saluja

Hi Mr. @Pixep, I already started working on this issue.. but I found guys asking for "assigning" .. my question is it a must to get assigned before start contributing ?

i-Sa3ed avatar Feb 25 '23 09:02 i-Sa3ed

Hi everyone, i don't believe we have precise rules around contributions, and issues don't have to be assigned to be worked on, but I would recommend waiting for @PaarthAgarwal 's, who was the first to comment here, to avoid duplicating effort. @PaarthAgarwal is this something you are working on?

Pixep avatar Feb 25 '23 16:02 Pixep

Yes I am. Will open a PR tomorrow most certainly

PaarthAgarwal avatar Feb 25 '23 16:02 PaarthAgarwal

@PaarthAgarwal let me know if you need some help resolving this issue CC: @Pixep

ashutosh887 avatar Feb 25 '23 17:02 ashutosh887

I want to contribute in it please assign it to me and also if you don't mind will you please explain me about the issue. Its a humble request

Danish9113 avatar Feb 27 '23 18:02 Danish9113

@Pixep I got stuck while working on the issue and I think it'll take me more time to understand the codebase. You can assign this issue to others who are interested to work on it

PaarthAgarwal avatar Feb 27 '23 18:02 PaarthAgarwal

I found some issues with Global declarations. How can I proceed with documenting them?

Rohan1Saluja avatar Feb 27 '23 18:02 Rohan1Saluja

@Pixep I got stuck while working on the issue and I think it'll take me more time to understand the codebase. You can assign this issue to others who are interested to work on it

How long do you think you would need @PaarthAgarwal ? I don't think we are in a hurry, as long as we can make progress, so it is up to you.

Pixep avatar Feb 27 '23 18:02 Pixep

@Pixep I'm next on the queue, let me try.

ashutosh887 avatar Feb 27 '23 18:02 ashutosh887

@Pixep I got stuck while working on the issue and I think it'll take me more time to understand the codebase. You can assign this issue to others who are interested to work on it

How long do you think you would need @PaarthAgarwal ? I don't think we are in a hurry, as long as we can make progress, so it is up to you.

I don't know. Perhaps issues regarding web development are more suited for me. For example while setting up this project I found documentation to install bazel for Linux Ubuntu inadequate. Would like do to a PR for the same

PaarthAgarwal avatar Feb 27 '23 18:02 PaarthAgarwal

Alright in that case we can open it to someone else if that is OK with you. People can contribute by reviewing the language design, providing feedback, and working on the Explorer or toolchain, but none are web-related as far as I know, see README.md.

Pixep avatar Mar 01 '23 17:03 Pixep

@Pixep should I try for it, Since this issue is open for a long time and is waiting to be completed so you can assign it to me.

AbhishekCS3459 avatar Mar 06 '23 13:03 AbhishekCS3459

Hi @Pixep sir ,I'm interested in working on this and contributing to Carbon Language.

Kaustubhkongile avatar Mar 26 '23 19:03 Kaustubhkongile

Removing "good first issue" here since we're talking about archiving the explorer.

jonmeow avatar Nov 28 '23 17:11 jonmeow

Closing explorer-specific issues as not-planned for now due to our decision to prioritize working on the toolchain over other implementation work in the near term: https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p3532.md

chandlerc avatar Jan 20 '24 00:01 chandlerc