Dear Dambaev,
On Sun, Aug 30, 2020 at 2:10 PM Dambaev Alexander <
ice.r...@gmail.com> wrote:
> 1. the reason why we need to prove, that x = addr@opts is that shared_unref's type says, that it's return type defines some 'l':
> ```
> extern fun shared_unref{a:vt@ype} (shared(a)): [l:addr][c:int] (option_v(a@l, c <= 1) | ptr l, int c)
> ```
> this l can be the same as addr@opts, but can be some other, so we need to check;
If we can write it as follows, `assertloc(x = addr@opts)` isn't needed?
```ats
absvtype shared{l:addr}(a:vt@ype) = (a@l | ptr l)
```
> 2. For now I can only guess why version with view@ didn't work (maybe Hongwei will tell us the actual reason, especially if this is a bug or a feature), but I think it is related to how both views are behave:
OK. Thank you for your note.
> when we consume view@opts in make_shared, view@opts is still available at 'main' and we can show it's type with '$showtype', which tells us, that now it is ' without(ip6_pktopt) @ opts'
>
> ```
> **SHOWTYPE[UP]**(/data/devel/ats2/closure/main.dats: 2970(line=109, offs=26) -- 2979(line=109, offs=35)): S2Eat(S2Ewithout(S2Etyrec(flt0; npf=-1; ip6po_hlim=S2Etop(knd=0; S2Ecst(int)))); S2Evar(opts(8624))): S2RTbas(S2RTBASimp(7; view))
> ```
>
> but if we will use view alias like this:
> ```
> implement main0 () = let
> var opts: ip6_pktopts with opts_pf
> var inp: inpcb
> val () = inp.in6p_outputopts := addr@opts
> prval _ = $showtype (opts_pf)
> val () = inp.sh := shared_make(opts_pf | addr@opts)
> val (pf_oopts | x, count) = shared_unref(inp.sh)
> val () = assertloc(count <= 1)
> prval Some_v(pf_opts) = pf_oopts
> val () = assertloc( x = addr@opts)
> (* prval _ = $showtype (opts_pf) can't use it here, because opts_pf is no longer available, as it was consumed *)
> prval () = opts_pf := pf_opts (* restore opts_pf *)
> prval _ = $showtype (opts_pf)
> in
> ignoret(usleep(1000u))
> end
> ```
> it will show types:
> ```
> **SHOWTYPE[UP]**(/data/devel/ats2/closure/main.dats: 2733(line=103, offs=26) -- 2740(line=103, offs=33)): S2Eat(S2Etyrec(flt0; npf=-1; ip6po_hlim=S2Etop(knd=0; S2Ecst(int))); S2Evar(opts(8624))): S2RTbas(S2RTBASimp(7; view))
> **SHOWTYPE[UP]**(/data/devel/ats2/closure/main.dats: 3021(line=110, offs=26) -- 3028(line=110, offs=33)): S2Eat(S2EVar(5372); S2Evar(l$8793$8795(14582))): S2RTbas(S2RTBASimp(7; view))
> ```
> meaning, that we no longer have a prove of 'ip6_pktopt @ opts', but we have a prove of 'ip6_pktopt @ l', where l is some address, even though we have an assertloc(), that should confirn, that 'l = addr@opts'.
> It may be, that for compiler 'opts' is not a pointer, but a variable and that is why we can't prove that l = opts, but in case of using view alias, compiler thinks 'ok, prove with '@opts' has gone now and we got new proof with some 'l', it's type 'a' is the same as type of 'opts', so it is the same size and I can replace consumed view with that one'.
Umm... Sorry. I can't understand why the `addr@opts`s are same with
`assertloc()`, on `$showtype` output...
I need to learn more to read ATS2 type messages.
Thank you,