Giter VIP home page Giter VIP logo

Comments (6)

mfelsche avatar mfelsche commented on July 17, 2024

One humble suggestion for sparking the discussion:

To ease the step to getting a reflection API up and running for pony, maybe it is worth to get things started with a really basic version that is only able to output the type name of a class.

It might be implemented as some kind of Type class/primitive that represents the type of an object as the compiler sees it.

An example API

// example with type method generated for every class/primitive
let myStringRef: (Stringable & ByteSeq) = "abc"
let type: Type = myStringRef.type()
let typeName = type.name() // "String"

// example with Reflection primitive
let myRefWithTypeParams: Array[String] = ["abc"; "def"]
let type: Type = Reflection.type(myRefWithTypeParams)
let typeName = type.name() // "Array[String]"

Getting the type from an object reference might not need to involve any capability checking or Auth as long as the type is as simple as outlined above.

Such a Type could also provide access the Types of the traits of an object. I am not sure if it possible to access implemented interfaces, but it sure would be a nice feature of a Type class.

trait Type
   fun name(): String
   fun traits(): Seq[Type]
   fun interfaces(): Seq[Type]

Given that this is very barebones, i think it is necessary to make sure that its design doesn't contradict with the vision of the full reflection API. So it will be easy to just extend the given types and methods without breaking changes if possible.

from rfcs.

niclash avatar niclash commented on July 17, 2024

I think that the first step is an Introspection API, rather than the full-fledged Reflection system found in Java and elsewhere, where you can modify values willy-nilly which will violate compiler type/data-race safety. And perhaps reading values are also left out for that reason, but calling behaviors and constructors should be ok (I think).

IF (this part is unclear to me atm) there is only a "compile all from source" option, i.e. no libraries, then the compiler can determine (by encountering call to Introspection) whether the Introspection Meta-info should be included in the binary or not.

I would like to propose a little bit more of "barebones" than @mfelsche above. Since I am not at all proficient in Pony yet, I am sure there are many things that I have misunderstood, so please bear with me, but I think it is a reasonable starting point from someone who has extensive experience with reflection in Java (all the way back to when Reflection API was introduced in Java 1.1 (1997))

I don't think we should burden all types with type() function, but simply have a type_of() in the Introspection API, since more often than not, this is not used.

I think(!) the stuff below is not inflicting complications on the type system guarantees, as only behaviors can be invoked and constructors to be called.


trait Introspection
    fun package(name:String): Package val
    fun type_of(object: (Object | None) ): Type val

trait Package
    fun name(): String val
    fun members(): Seq[Type] val

trait Type
    fun package(): Seq[Package] val
    fun name(): String val
    fun traits(): Seq[Type] val
    fun declared_interfaces(): Seq[Type] val
    fun implements_interface(intface: Type): Bool val
    fun is_private(): Bool val
    fun is_actor(): Bool val
    fun is_class(): Bool val
    fun is_primitive(): Bool val
    fun is_type(): Bool val
    fun is_struct(): Bool val
    fun is_array(): Bool val
    fun is_union(): Bool val
    fun is_intersection(): Bool val
    fun fields(): Seq[Alias] val
    fun functions(): Seq[Function] val
    fun constructors(): Seq[Constructor] val

trait Actor is Type
    fun behaviors(): Seq[Behavior] val

trait UnionType is Type
    fun members(): Seq[Type] val

trait IntersectionType is Type
    fun members(): Seq[Type] val

trait Alias
    fun name(): String val
    fun capability(): Capability val
    fun is_private(): Bool val

trait Tuple
    fun aliases(): Seq[Alias] val

trait Function
    fun name(): String val
    fun capability(): Capability val
    fun parameters(): Seq[(Alias | Tuple | Lambda)] val   // can tuples be passed as arguments?
    fun returns(): (Alias | Tuple | Lambda) val
    fun is_private(): Bool val

trait Lambda is Function

trait Behavior is Function 
    fun invoke( actor:Object tag, args: Array[Object] )

trait Constructor[T:Type] is Function 
    fun apply( args: Array[Object] ) : T ref^

type Capability is ( Iso | Val | Ref | Box | Trn | Tag )

primitive Iso 
primitive Val 
primitive Ref 
primitive Box 
primitive Trn 
primitive Tag

from rfcs.

SeanTAllen avatar SeanTAllen commented on July 17, 2024

I don't much like the idea of having traits/interfaces that you have to opt into. I'm also not a fan of segmenting off a large chunk of namespacing like name where no class can have name as a method because it would conflict with reflection/introspection.

It would result in a lot of code breakage.

On a user API side, I'd rather see some combination of primitives that can be passed Pony objects like instances of a class, actor, etc and extract information from it via something that I think would be using a c-api to hooked into information generated at compile time.

from rfcs.

niclash avatar niclash commented on July 17, 2024

from rfcs.

SeanTAllen avatar SeanTAllen commented on July 17, 2024

@niclash what would implement these traits that you propose?

Perhaps I was mislead by your usage of trait in your example and that wasn't what you were intending.

from rfcs.

niclash avatar niclash commented on July 17, 2024

from rfcs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.