# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


from base import *
from globs import *
from types_builtin import app_map, subst
        if destData is not None:
            ctor = transmuted_ctor(src, destData)
            ctor_cls = extrinsic(TrueRepresentation, ctor)

    o = ctor_cls(*fs)

    for extr in vat.copiedExtrinsics:
        if has_extrinsic(extr, src):
            add_extrinsic(extr, o, extrinsic(extr, src))

    if in_extrinsic_scope(Original):
        set_orig(o, src)
    vat.replacements[src] = o

    return o

def clone_by_type(src, t):
    cls = t.__class__
    if cls is TVar:
        assert isinstance(Structured, src), \
                "Can't clone unstructured %r without type info" % (src,)
        return clone_structured(src)
    elif cls in (TPrim, TFunc, TWeak):
        return src
    elif cls is TTuple:
        assert isinstance(src, tuple)
        return tuple(clone_by_type(v, tt) for v, tt in ezip(src, t.tupleTypes))
    elif cls is TData:
        assert isinstance(src, extrinsic(TrueRepresentation, t.data)), \
                "Expected %s, got: %r" % (t.data, obj)

# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


# Path: vat.py
from base import *
from globs import *
from types_builtin import app_map, subst

        if destData is not None:
            ctor = transmuted_ctor(src, destData)
            ctor_cls = extrinsic(TrueRepresentation, ctor)

    o = ctor_cls(*fs)

    for extr in vat.copiedExtrinsics:
        if has_extrinsic(extr, src):
            add_extrinsic(extr, o, extrinsic(extr, src))

    if in_extrinsic_scope(Original):
        set_orig(o, src)
    vat.replacements[src] = o

    return o

def clone_by_type(src, t):
    cls = t.__class__
    if cls is TVar:
        assert isinstance(Structured, src), \
                "Can't clone unstructured %r without type info" % (src,)
        return clone_structured(src)
    elif cls in (TPrim, TFunc, TWeak):
        return src
    elif cls is TTuple:
        assert isinstance(src, tuple)
        return tuple(clone_by_type(v, tt) for v, tt in ezip(src, t.tupleTypes))
    elif cls is TData:
        assert isinstance(src, extrinsic(TrueRepresentation, t.data)), \
                "Expected %s, got: %r" % (t.data, obj)

        apps = t.appTypes and app_map(t.data, t.appTypes)