Re: compiler types: records / collections interaction
Kon Lovett <[email protected]>
| Newsgroups | gmane.lisp.scheme.chicken |
|---|---|
| Message-ID | <[email protected]> |
> On Feb 9, 2024, at 11:59 AM, Al <[email protected]> wrote: > > Suppose I need a record of a record type myrec, and collections (vectors-of, lists-of and hash-tables) with values myrec. (define-type myrec (struct myrec)) (define-type myrec-vec (vector-of myrec)) (: myrv-ref (myrec-vec fixnum —> myrec) (define myrv-ref vector-ref) > > > What combination of > > * define-record-type (srfi-9, srfi-99, chicken define-record, whatever) and > > * (declare type ...) > > can I use to inform the compiler that (for collections of myrec) vector-ref returns myrec's (likewise list car/cdr, hash-table-ref)? And that it needs not emit any instance-type-checking code for objects extracted from such collections? > > > Furthermore, how can I see what the compiler thinks of a given identifier? I've used 'csc -ot' but it only emits types for some identifiers. Maybe it inlines others, I don't really know. > > > Separately, how can I tell the compiler that fields in these records have certain types? Add type declarations for the implicitly-defined per-field accessors and mutators? (import typed-records) (define-record myrec (a : float) (b : symbol)) does this for you (: make-myrec (float symbol -> (struct myrec))) (: myrec? (* -> boolean : (struct myrec))) (: myrec-a ((struct myrec) -> float)) (: myrec-b ((struct myrec) -> symbol)) > > > I've tried unwrapping collections of myrec, and also myrec fields, and it seems to make a huge difference in the speed of compiled code. Presumably because I don't know how to tell the compiler to omit type checking in "safe" cases. I know I could use some of the more aggressive optimization levels, but I don't really want to compile unsafe code everywhere, just where I'm using the correct types. > > > Thanks, > > Al > >