forked from hyeyoungshin/talk-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-linking-types.html
486 lines (483 loc) · 19 KB
/
script-linking-types.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>script-linking-types</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
jax: ["input/TeX","output/HTML-CSS"],
extensions: [],
TeX: {
extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
},
showMathMenu: false
});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js">
</script>
<style>
.conflict-resolved {
background: #31363f;
}
.conflict-ours {
background: rgba(0, 136, 255, 0.4);
}
.conflict-ours.cursor-line {
background: rgba(0, 136, 255, 0.3);
}
.conflict-theirs {
background: rgba(32, 182, 132, 0.4);
}
.conflict-theirs.cursor-line {
background: rgba(32, 182, 132, 0.3);
}
.conflict-base {
background: rgba(204, 133, 51, 0.4);
}
.conflict-base.cursor-line {
background: rgba(204, 133, 51, 0.3);
}
.conflict-dirty {
background: rgba(235, 221, 91, 0.4);
}
.conflict-dirty.cursor-line {
background: rgba(235, 221, 91, 0.3);
}
.bracket-matcher .region {
border-bottom: 1px dotted lime;
position: absolute;
}
.spell-check-misspelling .region {
border-bottom: 2px dotted rgba(255, 51, 51, 0.75);
}
.spell-check-corrections {
width: 25em !important;
}
pre.editor-colors {
background-color: #282c34;
color: #abb2bf;
}
pre.editor-colors .line.cursor-line {
background-color: rgba(153, 187, 255, 0.04);
}
pre.editor-colors .invisible {
color: #abb2bf;
}
pre.editor-colors .cursor {
border-left: 2px solid #528bff;
}
pre.editor-colors .selection .region {
background-color: #3e4451;
}
pre.editor-colors .bracket-matcher .region {
border-bottom: 1px solid #528bff;
box-sizing: border-box;
}
pre.editor-colors .invisible-character {
color: rgba(171, 178, 191, 0.15);
}
pre.editor-colors .indent-guide {
color: rgba(171, 178, 191, 0.15);
}
pre.editor-colors .wrap-guide {
background-color: rgba(171, 178, 191, 0.15);
}
pre.editor-colors .find-result .region.region.region,
pre.editor-colors .current-result .region.region.region {
border-radius: 2px;
background-color: rgba(82, 139, 255, 0.24);
transition: border-color 0.4s;
}
pre.editor-colors .find-result .region.region.region {
border: 2px solid transparent;
}
pre.editor-colors .current-result .region.region.region {
border: 2px solid #528bff;
transition-duration: .1s;
}
pre.editor-colors .gutter .line-number {
color: #636d83;
-webkit-font-smoothing: antialiased;
}
pre.editor-colors .gutter .line-number.cursor-line {
color: #abb2bf;
background-color: #2c313a;
}
pre.editor-colors .gutter .line-number.cursor-line-no-selection {
background-color: transparent;
}
pre.editor-colors .gutter .line-number .icon-right {
color: #abb2bf;
}
pre.editor-colors .gutter:not(.git-diff-icon) .line-number.git-line-removed.git-line-removed::before {
bottom: -3px;
}
pre.editor-colors .gutter:not(.git-diff-icon) .line-number.git-line-removed::after {
content: "";
position: absolute;
left: 0px;
bottom: 0px;
width: 25px;
border-bottom: 1px dotted rgba(224, 82, 82, 0.5);
pointer-events: none;
}
pre.editor-colors .gutter .line-number.folded,
pre.editor-colors .gutter .line-number:after,
pre.editor-colors .fold-marker:after {
color: #abb2bf;
}
.syntax--comment {
color: #5c6370;
font-style: italic;
}
.syntax--comment .syntax--markup.syntax--link {
color: #5c6370;
}
.syntax--entity.syntax--name.syntax--type {
color: #e5c07b;
}
.syntax--entity.syntax--other.syntax--inherited-class {
color: #98c379;
}
.syntax--keyword {
color: #c678dd;
}
.syntax--keyword.syntax--control {
color: #c678dd;
}
.syntax--keyword.syntax--operator {
color: #abb2bf;
}
.syntax--keyword.syntax--other.syntax--special-method {
color: #61afef;
}
.syntax--keyword.syntax--other.syntax--unit {
color: #d19a66;
}
.syntax--storage {
color: #c678dd;
}
.syntax--storage.syntax--type.syntax--annotation,
.syntax--storage.syntax--type.syntax--primitive {
color: #c678dd;
}
.syntax--storage.syntax--modifier.syntax--package,
.syntax--storage.syntax--modifier.syntax--import {
color: #abb2bf;
}
.syntax--constant {
color: #d19a66;
}
.syntax--constant.syntax--variable {
color: #d19a66;
}
.syntax--constant.syntax--character.syntax--escape {
color: #56b6c2;
}
.syntax--constant.syntax--numeric {
color: #d19a66;
}
.syntax--constant.syntax--other.syntax--color {
color: #56b6c2;
}
.syntax--constant.syntax--other.syntax--symbol {
color: #56b6c2;
}
.syntax--variable {
color: #e06c75;
}
.syntax--variable.syntax--interpolation {
color: #be5046;
}
.syntax--variable.syntax--parameter {
color: #abb2bf;
}
.syntax--string {
color: #98c379;
}
.syntax--string.syntax--regexp {
color: #56b6c2;
}
.syntax--string.syntax--regexp .syntax--source.syntax--ruby.syntax--embedded {
color: #e5c07b;
}
.syntax--string.syntax--other.syntax--link {
color: #e06c75;
}
.syntax--punctuation.syntax--definition.syntax--comment {
color: #5c6370;
}
.syntax--punctuation.syntax--definition.syntax--method-parameters,
.syntax--punctuation.syntax--definition.syntax--function-parameters,
.syntax--punctuation.syntax--definition.syntax--parameters,
.syntax--punctuation.syntax--definition.syntax--separator,
.syntax--punctuation.syntax--definition.syntax--seperator,
.syntax--punctuation.syntax--definition.syntax--array {
color: #abb2bf;
}
.syntax--punctuation.syntax--definition.syntax--heading,
.syntax--punctuation.syntax--definition.syntax--identity {
color: #61afef;
}
.syntax--punctuation.syntax--definition.syntax--bold {
color: #e5c07b;
font-weight: bold;
}
.syntax--punctuation.syntax--definition.syntax--italic {
color: #c678dd;
font-style: italic;
}
.syntax--punctuation.syntax--section.syntax--embedded {
color: #be5046;
}
.syntax--punctuation.syntax--section.syntax--method,
.syntax--punctuation.syntax--section.syntax--class,
.syntax--punctuation.syntax--section.syntax--inner-class {
color: #abb2bf;
}
.syntax--support.syntax--class {
color: #e5c07b;
}
.syntax--support.syntax--type {
color: #56b6c2;
}
.syntax--support.syntax--function {
color: #56b6c2;
}
.syntax--support.syntax--function.syntax--any-method {
color: #61afef;
}
.syntax--entity.syntax--name.syntax--function {
color: #61afef;
}
.syntax--entity.syntax--name.syntax--class,
.syntax--entity.syntax--name.syntax--type.syntax--class {
color: #e5c07b;
}
.syntax--entity.syntax--name.syntax--section {
color: #61afef;
}
.syntax--entity.syntax--name.syntax--tag {
color: #e06c75;
}
.syntax--entity.syntax--other.syntax--attribute-name {
color: #d19a66;
}
.syntax--entity.syntax--other.syntax--attribute-name.syntax--id {
color: #61afef;
}
.syntax--meta.syntax--class {
color: #e5c07b;
}
.syntax--meta.syntax--class.syntax--body {
color: #abb2bf;
}
.syntax--meta.syntax--method-call,
.syntax--meta.syntax--method {
color: #abb2bf;
}
.syntax--meta.syntax--definition.syntax--variable {
color: #e06c75;
}
.syntax--meta.syntax--link {
color: #d19a66;
}
.syntax--meta.syntax--require {
color: #61afef;
}
.syntax--meta.syntax--selector {
color: #c678dd;
}
.syntax--meta.syntax--separator {
background-color: #373b41;
color: #abb2bf;
}
.syntax--meta.syntax--tag {
color: #abb2bf;
}
.syntax--underline {
text-decoration: underline;
}
.syntax--none {
color: #abb2bf;
}
.syntax--invalid.syntax--deprecated {
color: #523d14 !important;
background-color: #e0c285 !important;
}
.syntax--invalid.syntax--illegal {
color: #ffffff !important;
background-color: #e05252 !important;
}
.syntax--markup.syntax--bold {
color: #d19a66;
font-weight: bold;
}
.syntax--markup.syntax--changed {
color: #c678dd;
}
.syntax--markup.syntax--deleted {
color: #e06c75;
}
.syntax--markup.syntax--italic {
color: #c678dd;
font-style: italic;
}
.syntax--markup.syntax--heading {
color: #e06c75;
}
.syntax--markup.syntax--heading .syntax--punctuation.syntax--definition.syntax--heading {
color: #61afef;
}
.syntax--markup.syntax--link {
color: #56b6c2;
}
.syntax--markup.syntax--inserted {
color: #98c379;
}
.syntax--markup.syntax--quote {
color: #d19a66;
}
.syntax--markup.syntax--raw {
color: #98c379;
}
.syntax--source.syntax--c .syntax--keyword.syntax--operator {
color: #c678dd;
}
.syntax--source.syntax--cpp .syntax--keyword.syntax--operator {
color: #c678dd;
}
.syntax--source.syntax--cs .syntax--keyword.syntax--operator {
color: #c678dd;
}
.syntax--source.syntax--css .syntax--property-name,
.syntax--source.syntax--css .syntax--property-value {
color: #828997;
}
.syntax--source.syntax--css .syntax--property-name.syntax--support,
.syntax--source.syntax--css .syntax--property-value.syntax--support {
color: #abb2bf;
}
.syntax--source.syntax--gfm .syntax--markup {
-webkit-font-smoothing: auto;
}
.syntax--source.syntax--gfm .syntax--link .syntax--entity {
color: #61afef;
}
.syntax--source.syntax--go .syntax--storage.syntax--type.syntax--string {
color: #c678dd;
}
.syntax--source.syntax--ini .syntax--keyword.syntax--other.syntax--definition.syntax--ini {
color: #e06c75;
}
.syntax--source.syntax--java .syntax--storage.syntax--modifier.syntax--import {
color: #e5c07b;
}
.syntax--source.syntax--java .syntax--storage.syntax--type {
color: #e5c07b;
}
.syntax--source.syntax--java .syntax--keyword.syntax--operator.syntax--instanceof {
color: #c678dd;
}
.syntax--source.syntax--java-properties .syntax--meta.syntax--key-pair {
color: #e06c75;
}
.syntax--source.syntax--java-properties .syntax--meta.syntax--key-pair > .syntax--punctuation {
color: #abb2bf;
}
.syntax--source.syntax--js .syntax--keyword.syntax--operator {
color: #56b6c2;
}
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--delete,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--in,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--of,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--instanceof,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--new,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--typeof,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--void {
color: #c678dd;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--string.syntax--quoted.syntax--json {
color: #e06c75;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation.syntax--string {
color: #e06c75;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--array.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--array.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation {
color: #98c379;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--constant.syntax--language.syntax--json,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--array.syntax--json > .syntax--constant.syntax--language.syntax--json {
color: #56b6c2;
}
.syntax--source.syntax--ruby .syntax--constant.syntax--other.syntax--symbol > .syntax--punctuation {
color: inherit;
}
.syntax--source.syntax--python .syntax--keyword.syntax--operator.syntax--logical.syntax--python {
color: #c678dd;
}
.syntax--source.syntax--python .syntax--variable.syntax--parameter {
color: #d19a66;
}
</style>
</head>
<body class='markdown-preview'><p>In a large-scale software system, each part of the system is responsible for
a specific task and is, therefore, often written in a language that is best suited for that task.
This is a problem because as programmers develop complex systems, they spend much time refactoring.
(making changes to components that should result in equivalent behavior.)</p>
<p>Unfortunately, in a refactoring process programmers cannot solely rely on contextual equivalence of
their own language. Since different languages interact after they have been compiled to
a target language, programmers have to take the contexts that is inexpressible in their source language
but is expressible in the common target into account in their reasoning.</p>
<p>For example, even if a programmer is using a safe language like OCaml, the equivalence he/she relies
on in the source level can be disrupted by a C code that can be linked in a lower-level unsafe language.</p>
<p>We would like programmers to be able to reason using contextual equivalence in the language they used
even in the presence of target-level linking. A fully abstract compiler does this. If two components
are contextually equivalent at the source their compiled versions are contextually equivalent at the
target.</p>
<p>However, this comes at a steep cost: a fully abstract compiler disallow linking with components whose
behavior is inexpressible in the compiler’s source language. What if this extra behavior or control
is exactly what the programmer wants, but was not able to express in his/her source language?
Moreover, we want programmers to decide what kind of linking is necessary in his/her program, not
compiler writers.</p>
<p>(Similar work: cross-langauge linking is supported by Compositional Compcert, but it only allows
linking with components that satisfy CompCert’ memory model, Perconti and Ahmed’s multi-language
style of verified compilers, but a programmer needs to understand the full ST language and the
compiler from R to T.)</p>
<p>The method advocated in the paper is to extend source language specifications with linking types.
This is a better solution than previous works because we minimally enrich source language types
and allow programmers to annotate only when they want to link with inexpressible components in
their source language.</p>
<p>To introduce linking types formally, we consider two simple source languages. <span class="math"><script type="math/tex">\lambda</script></span> is the
simply typed lambda calculus with integer base types and <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}</script></span> extends <span class="math"><script type="math/tex">\lambda</script></span> with mutable
references. We want type-preserving fully abstract compilers from <span class="math"><script type="math/tex">\lambda</script></span> and <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}</script></span> to
a common target language. The target should have a rich enough type system to allow full abstract
type translation and to use types to rule out equivalence disrupting linking.</p>
<p>For example, our target <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}_{\mathrm{exn}}</script></span> has a modal type system that can distinguish pure computation
from impure computation, which then can be used to rule out linking \lambda with <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}</script></span> component
that uses mutable references. We also added exceptions to the target to represent the extra control
flow commonly found in low-level language.</p>
<p>Let me illustrate the linking idea with <span class="math"><script type="math/tex">e_1</script></span> and <span class="math"><script type="math/tex">e_2</script></span> here. These two programs are equivalent in <span class="math"><script type="math/tex">\lambda</script></span>.
Now consider the context <span class="math"><script type="math/tex">C^{\mathrm{ref}}</script></span> that implements a counter using a reference cell. The fully abstract
compiler would have to disallow linking between <span class="math"><script type="math/tex">e_1</script></span> and <span class="math"><script type="math/tex">e_2</script></span> with <span class="math"><script type="math/tex">C^{\mathrm{ref}}</script></span> since this linking disrupts
the equivalence. What if the programmer wants to link these together and is willing to give up some
equivalences in order to do so?</p>
<p>We present linking-types extension for <span class="math"><script type="math/tex">\lambda^{\kappa}</script></span> and <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}^{\kappa}}</script></span> to enable such linking.
The <span class="math"><script type="math/tex">\lambda^\kappa</script></span> type system includes reference types and tracks heap effects. It also includes
a computation type <span class="math"><script type="math/tex">R^\epsilon \tau</script></span> that will be compiled to the target computation type
<span class="math"><script type="math/tex">E^{\epsilon}_{\mathrm{exn}} \tau</script></span>. Additionally, we provide type conversion functions <span class="math"><script type="math/tex">\kappa^+</script></span> and <span class="math"><script type="math/tex">\kappa^-</script></span> to relate
types in <span class="math"><script type="math/tex">\lambda</script></span> and <span class="math"><script type="math/tex">\lambda^\kappa</script></span>.</p>
<p>With this extension, the programmer can annotate <span class="math"><script type="math/tex">e_1</script></span> and <span class="math"><script type="math/tex">e_2</script></span> with a linking type that specifies that
the input to these programs can be heap-effecting. At this type, <span class="math"><script type="math/tex">e_1</script></span> and <span class="math"><script type="math/tex">e_2</script></span> are no longer contextually
equivalent and further can be linked with <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}</script></span>'s the counter library.</p>
<p>Without the annotation, the compiler would translate the types of <span class="math"><script type="math/tex">e_1</script></span> and <span class="math"><script type="math/tex">e_2</script></span> which is the <span class="math"><script type="math/tex">\lambda</script></span> type
<code>unit -> int</code> to the <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}_{\mathrm{exn}}</script></span> type <code>unit -></code><span class="math"><script type="math/tex">E^0_O</script></span> and the type of counter which is the <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}</script></span>
type <code>unit -> int</code> to the <span class="math"><script type="math/tex">\lambda^{\mathrm{ref}}_{\mathrm{exn}}</script></span> type <code>unit -></code> <span class="math"><script type="math/tex">E^1_O</script></span> type. Since these types are not the same
an error would be reported and linking can’t happen.</p>
<p>By contrast, <span class="math"><script type="math/tex">\lambda^\kappa</script></span>'s type (<code>unit -> R^1 int) -> int</code> that the programmer annotate <span class="math"><script type="math/tex">e_1</script></span> and <span class="math"><script type="math/tex">e_2</script></span>
with will be translated to <code>(unit -> E^1_O int) -> E^1_O int</code> which is the same from the translation of
the counter library.</p></body>
</html>